Using "adb backup" to back up an application programmatically
I am currently backing up my app with a command adb backup
when my device connects to my computer via a micro usb cable. The command looks like this:
adb backup -f Backups/app.ab -noapk com.me.app
Which outputs and an android (ab) backup file called app.ab in my Backups folder.
I am wondering if it is possible to programmatically back up an application to an SD card? I just need to periodically back up the application and its databases.
Any links / docs on this would be helpful.
Thanks, Matt
source to share
You cannot run commands ADB
(for example backup
) from your application, but you can run commands SHELL
(commands LINUX
that run from within SHELL
), for example:
Process process = Runtime.getRuntime().exec("my_command");
If you know the target and target folders, you can use the command cp
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 appropriate permissions to write to SD
.
source to share