I am trying to copy apk of the user installed apps in a folder.
Here is the code
public void backUpApk(int position){
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try{
App app = getItem(position);
System.out.println("Source "+app.getApplicationInfo().sourceDir+File.separator+app.getLabel()+".apk");
File source = new File(app.getApplicationInfo().sourceDir+File.separator+app.getLabel()+".apk");
inputChannel = new FileInputStream(source).getChannel();
File destination = new File(Environment.getExternalStorageDirectory()+File.separator+ Constants.FOLDER_NAME);
outputChannel = new FileOutputStream(destination).getChannel();
outputChannel.transferFrom(inputChannel,0,inputChannel.size());
}catch (Exception e){
e.printStackTrace();
}
}
抛出NoReadableChannel异常。如何完成这项任务? 我可以像这样从系统目录复制apk吗?