如何从另一个应用程序获取apk文件到一个文件夹?

时间:2015-11-30 06:34:40

标签: java android

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吗?

0 个答案:

没有答案