|
@ -9,9 +9,11 @@ import android.content.ActivityNotFoundException;
|
9
|
9
|
import android.widget.Toast;
|
10
|
10
|
|
11
|
11
|
import com.ai.ipu.basic.file.FileUtil;
|
|
12
|
import com.ai.ipu.basic.string.StringUtil;
|
12
|
13
|
import com.ai.ipu.mobile.app.MobileOperation;
|
13
|
14
|
import com.ai.ipu.mobile.frame.IIpuMobile;
|
14
|
15
|
import com.ai.ipu.mobile.frame.plugin.Plugin;
|
|
16
|
import com.ai.ipu.mobile.frame.template.ResVersionManager;
|
15
|
17
|
import com.ai.ipu.mobile.util.DirectionUtil;
|
16
|
18
|
import com.ai.ipu.mobile.util.IpuMobileException;
|
17
|
19
|
|
|
@ -59,7 +61,26 @@ public class MobileFile extends Plugin{
|
59
|
61
|
}
|
60
|
62
|
return true;
|
61
|
63
|
}
|
62
|
|
|
|
64
|
|
|
65
|
/**
|
|
66
|
* 列出相对路径下的文件,返回JSONArray字符串
|
|
67
|
* @param param
|
|
68
|
* @throws Exception
|
|
69
|
*/
|
|
70
|
public void listDirFiles(JSONArray param) throws Exception {
|
|
71
|
String path = param.getString(0);//相对路径参数
|
|
72
|
String absolutePath = DirectionUtil.getInstance(context).getDirection(path, true);
|
|
73
|
File dir = new File(absolutePath);
|
|
74
|
String[] fileNames = dir.list();
|
|
75
|
JSONArray arr = new JSONArray();
|
|
76
|
if (fileNames!=null) {
|
|
77
|
for(String name : fileNames){
|
|
78
|
arr.put(name);
|
|
79
|
}
|
|
80
|
}
|
|
81
|
callback(arr.toString());
|
|
82
|
}
|
|
83
|
|
63
|
84
|
public void getAllFile(JSONArray param) throws Exception{
|
64
|
85
|
String fileName = param.getString(0); //相对路径参数
|
65
|
86
|
String type = param.getString(1);
|
|
@ -109,11 +130,11 @@ public class MobileFile extends Plugin{
|
109
|
130
|
String type = param.getString(1);
|
110
|
131
|
Boolean isSdcard = "true".equals(param.getString(2));
|
111
|
132
|
Boolean isEncode = param.getBoolean(3);
|
112
|
|
String relativePath = DirectionUtil.getInstance(context).getRelativePath(fileName, type);
|
|
133
|
String relativePath = DirectionUtil.getInstance(context).getRelativePath(fileName, type);
|
113
|
134
|
try {
|
114
|
135
|
String absolutePath = util.getDirection(relativePath, isSdcard == null ? true : isSdcard);
|
115
|
136
|
String value = FileUtil.readFile(absolutePath);
|
116
|
|
callback(value);
|
|
137
|
callback(value);
|
117
|
138
|
} catch (Exception e) {
|
118
|
139
|
throw new IpuMobileException(e);
|
119
|
140
|
}
|
|
@ -159,17 +180,35 @@ public class MobileFile extends Plugin{
|
159
|
180
|
callback(relativePath);
|
160
|
181
|
}
|
161
|
182
|
|
162
|
|
//删除文件
|
|
183
|
/**
|
|
184
|
* 删除文件
|
|
185
|
* @param param [fileName, type, isSdCard]。
|
|
186
|
* type可传"file","audio","image","video",指定删除对应目录下的文件
|
|
187
|
* 也可传"force",代表不限制以上目录,强制删除。
|
|
188
|
* @throws Exception e
|
|
189
|
*/
|
163
|
190
|
public void deleteFile(JSONArray param) throws Exception{
|
164
|
191
|
String fileName = param.getString(0); //相对路径参数
|
165
|
|
String type = param.getString(1);
|
|
192
|
String type = param.optString(1);
|
166
|
193
|
boolean isSdcard = "true".equals(param.getString(2));
|
167
|
|
String relativePath = DirectionUtil.getInstance(context).getRelativePath(fileName, type);
|
168
|
|
deleteFile(relativePath, isSdcard);
|
|
194
|
String relativePath = null;
|
|
195
|
if ("force".equals(type)) {
|
|
196
|
deleteFile(fileName, isSdcard);
|
|
197
|
} else {
|
|
198
|
relativePath = DirectionUtil.getInstance(context).getRelativePath(fileName, type);
|
|
199
|
if (relativePath == null) {
|
|
200
|
error("delete params error");
|
|
201
|
return;
|
|
202
|
}
|
|
203
|
deleteFile(relativePath, isSdcard);
|
|
204
|
}
|
169
|
205
|
}
|
170
|
206
|
|
171
|
207
|
public void deleteFile(String relativePath, boolean isSdcard){
|
172
|
208
|
String absolutePath = util.getDirection(relativePath, isSdcard);
|
173
|
|
FileUtil.deleteFile(absolutePath);
|
|
209
|
boolean res = FileUtil.deleteFile(absolutePath);
|
|
210
|
if (!res) {
|
|
211
|
error("delete failed");
|
|
212
|
}
|
174
|
213
|
}
|
175
|
214
|
}
|