我有个问题。我有一个 ListView 和一个显示“复制”的上下文菜单。我希望当我单击“复制”时获取 APK 并从数据 / 应用程序移动到存储 / 模拟 / 0 / APK。我有这个代码。
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
final long examId = info.id;
ApplicationInfo app = applist.get((int) info.id);
switch (item.getItemId()) {
case COPY:
{
try{
File f1 = new File("/data/app"+app.packageName);
File f2 = new File("storage/emulated/0/APK");
InputStream in = new FileInputStream(f1);
//For Append the file.
// OutputStream out = new FileOutputStream(f2,true);
//For Overwrite the file.
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
Toast.makeText(getBaseContext(), "Success", Toast.LENGTH_SHORT).show();
}
catch(FileNotFoundException ex){
Toast.makeText(getBaseContext(), ex.getMessage() + " in the specified directory.", Toast.LENGTH_SHORT).show();
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
return true;
}
}
当我单击 Copy: /data/appcom.NameOfPackage.Package: open failed: ENOENT (No such file or directory) 在指定目录中时,我得到了这个 toast。
我该如何解决?我希望当我单击复制时,将 APK 应用程序从 /data /app 移动到 /storage/emulated/0/APK