java - 如何等到文件从系统目录复制到具有root访问权限的外部存储
问题描述
我有来自下一个路径/data/data/com.google.chrome/examplefile.txt
的文件:,我想通过路径复制文件:/sdcard/examplefile.txt
并与他一起执行操作,但文件大小:7 MB,这需要时间。我想复制文件等到他复制并与他一起执行操作。
我有超级用户访问权限(Root),并且从 /data/data 目录复制文件需要 root 访问权限。
解决方案
使用 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
}
}
}
推荐阅读
- javascript - React.js TypeError:模块不是函数
- angular - 如何以角度保存作为字节 [] 提供的文件?
- python - 在烧瓶中打印 python 返回
- selenium-webdriver - (SessionNotCreatedException) 会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 83
- python - 无法理解python装饰器功能
- python - 整个函数等待而不是某些进程等待
- c++ - 为什么 `file_pointer{0}` 编译但 `file_pointer(0)` 不编译?
- python - 对字典列表中的每个字典进行排序,分别按其值 - Python
- python - 从提取的 zip 文件中记录 xls 和 xlsx 文件位置
- javascript - 如何检测其他对象的状态