目前,我正在使用adb backup命令执行应用程序的adb backup ,我的设备通过micro usb电缆连接到我的电脑。 该命令如下所示:
adb backup -f Backups/app.ab -noapk com.me.app哪个输出和android备份(ab)文件在我的备份文件夹中称为app.ab.
我想知道是否可以通过编程方式将应用程序备份到SD卡? 我只需要定期备份应用程序及其数据库。
有关此问题的任何链接/文档都会有所帮助。
谢谢,马特
Currently, I'm performing backups of my application using the adb backup command with my device connect to my pc via a micro usb cable. The command looks like as follows:
adb backup -f Backups/app.ab -noapk com.me.appWhich outputs and android backup (ab) file called app.ab in my Backups folder.
I'm wondering if it's possible to backup an app to the SD Card programmatically? I just need to backup the app and it's databases periodically.
Any links/docs on this issue would be helpful.
Thanks, Matt
最满意答案
您无法从应用程序运行ADB命令(如backup ),但您可以运行SHELL命令(从SHELL内部运行的LINUX命令),如下所示 -
Process process = Runtime.getRuntime().exec("my_command");如果您知道目标和目标文件夹,则可以使用cp命令复制文件。 如果要读取命令的结果,请使用
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));确保您的应用具有写入SD的适当权限。
You can't run ADB commands (like backup) from your application, but you can run SHELL commands (the LINUX commands that run from inside the SHELL), like this -
Process process = Runtime.getRuntime().exec("my_command");If you know your target and destination folders, you can use cp command to copy files. If you want to read the results of your commands, use
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));Make sure your app has the proper permissions for writing to the SD.
更多推荐
发布评论