私は問題があります。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)] をクリックすると、このトーストが表示されます。
どうすれば修正できますか?コピーをクリックすると、APK アプリケーションを取得し、/data /app から / storage/emulated/0/APK に移動します。