Check and enable AutoBackUp to google drive from inside android app

Viewed 308

Is it possible to check if a user has enabled google's auto-backup feature from inside an app and give them the option to switch it on or off? If so could someone please provide a blueprint of how to implement this feature, as the google documentation is not providing any clarity on this matter?

2 Answers

A possible answer is that your application will participate in auto-backup if you have enabled the allow backup functionality in the manifest, but you can if you disabled it and want to upload the backup on your own will then you can do so by using BackupAgent visit here to see more. More information about allowBackup="true" here, in-depth detail about BackupAgent here

<manifest ... >
    ...
    <application android:allowBackup="false" ... >
        ...
    </application>
</manifest>

this should clarify your question and needs to implement the manual backup and provide all the functions necessary to achieve what you desire.

You could check programatically in your app with code like the following:

  PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
  if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0) {
     // it is enabled
  } else {
     // it is disabled
  }

Normally, it would be in the android manifest and under your control, but I'm guessing you have one of the following scenarios:

  • you are providing an SDK and want to check if the app using your SDK allows backup
  • you are concerned about somebody unpacking your app's apk, modifying the android:allowBackup and repacking your apk

As for changing the setting to enable backup (even if you check and find FLAG_ALLOW_BACKUP is false), I'm not aware of any way you can do that programmatically. But at least you can check the setting.

If you really still want to do a backup even if FLAG_ALLOW_BACKUP is false, you may need to write your own custom backup solution.

Related