首页 > 解决方案 > 如何等到文件从系统目录复制到具有root访问权限的外部存储

问题描述

我有来自下一个路径/data/data/com.google.chrome/examplefile.txt的文件:,我想通过路径复制文件:/sdcard/examplefile.txt并与他一起执行操作,但文件大小:7 MB,这需要时间。我想复制文件等到他复制并与他一起执行操作。

我有超级用户访问权限(Root),并且从 /data/data 目录复制文件需要 root 访问权限。

标签: javaandroidrootandroid-file

解决方案


使用 AsyncTask 在后台完成工作:

public class CopyFileTask extends AsyncTask <Void, Void, Void> {

    File file;

    public CopyFileTask () {
        file = null;
    }

    @Override
    protected Void doInBackground(Void... voids) {
        //Your code to copy the file here
        file = copyFileMethod();
        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        //If the file is not null, then that means you copied it
        if(file != null ){
        //Perform here the rest of the operations
        }
    }
}

推荐阅读