Android Key/Value Backup API sample code
https://developer.android.com/guide/topics/data/keyvaluebackup.html
*Use your own package name with an API key generated for it to run this sample with other than LocalTransport.
*No transports other than android/com.android.internal.backup.LocalTransport seems to be working :(
Create and enqueue a backup request
programmatically:
new BackupManager(context).dataChanged();adb:
adb shell bmgr backup <package name>At some point in the future, Android calls onBackup() to perform backups in the queue. To perform backups immediately for testing, use adb command:
adb shell bmgr runon successful backup, you'll see log messages in logcat (OR NOTHING ON A NEWER ANDROID):
V/BackupServiceBinder﹕ doBackup() invoked
D/BackupHelperDispatcher﹕ handling new helper 'myfiles'or this if it's not the first run
D/BackupHelperDispatcher﹕ handling existing helper 'myfiles' android.app.backup.FileBackupHelper@32ef2023at this point, uninstall the app and delete one.txt, two,txt, and three.txt from the disk. Resintall the app to see three files get restored. (*auto-restore must be anabled in Backup & reset in the system settings)
Restore from a backup
programmatically:
new BackupManager(context).requestRestore(callback); // restores immediatelyadb:
adb shell bmgr restore <package name>on success, you will see something like this:
restoreStarting: 1 packages
restoreFinished: 0
doneor on a newer android:
restoreStarting: 1 packages
onUpdate: 0 = org.mightyfrog.android.minimal.backupapi
restoreFinished: 0
donerestoreFinished other than 0 indicates an error: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/backup/BackupTransport.java
adb to list available transports:
adb shell list transportsyou will see two transports and one more if you have an enterprise account:
*android/com.android.internal.backup.LocalTransport
com.google.android.gms/.backup.BackupTransportService
com.android.server.enterprise/.EdmBackupTranspo* indicates the currently selected transport.
adb to select a transport to use:
adb shell transport android/com.android.internal.backup.LocalTransportadb to clear backups:
adb shell bmgr wipe <transport> <package name>