File in = new File("/data/app/" + packageName + ".apk"); File out = new File("/sdcard/BackupApp/" + packageName + ".apk"); out.createNewFile(); FileInputStream fis = new FileInputStream(in); FileOutputStream fos = new FileOutputStream(out);
int count; byte[] buffer = new byte[256 * 1024]; while ((count = fis.read(buffer)) > 0) { fos.write(buffer, 0, count); }
apk对应的包名,把里面的db,xml等文件拷贝到另一台手机上即可复制游戏数据了
如果你是想要手机里面的数据的话,可以在手机root后
这个什么意思,我没有找到这个文件夹,谢谢了
private void backupApp(String packageName) throws IOException {
File in = new File("/data/app/" + packageName + ".apk");
File out = new File("/sdcard/BackupApp/" + packageName + ".apk");
out.createNewFile();
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
int count;
byte[] buffer = new byte[256 * 1024];
while ((count = fis.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fis.close();
fos.flush();
fos.close();
}不需要任何额外的设置和权限。只要先获取所有程序的包名,然后依次传入上面的函数即可。
因为把程序备份到sdcard上,所以需要申请内存卡的读写权限。