使用“adb backup”以编程方式备份应用程序(Using 'adb backup' to backup application programmatically)

编程入门 行业动态 更新时间:2024-10-27 00:32:35
使用“adb backup”以编程方式备份应用程序(Using 'adb backup' to backup application programmatically)

目前,我正在使用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.app

Which 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.

更多推荐

本文发布于:2023-07-27 17:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   备份   方式   backup   adb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!