2

I have an assortment of files I don't want backed up via the new Marshmallow Autobackup feature - a Realm database, a Shared Prefs file I use to store "most recently seen" information, log files etc.

Rather than using <exclude ... /> for each of these, I'd prefer to simply back up the only file I do care about - user settings, stored in the default shared preferences. The docs indicate that using an <include ... /> will automatically exclude every file not explicitly included.

What path do I use for the default Shared Preferences file?

<full-backup-content>
    <include domain="sharedpref" path="?"/>
</full-backup-content>
Adam S
  • 16,144
  • 6
  • 54
  • 81

1 Answers1

6

As described here, the default shared preferences filename is your.package.name_preferences. You can see this by running the following ADB command after they've been accessed at least once:

adb shell run-as your.package.name ls -al shared_prefs

Outputs:

C:\Users\Adam>adb shell run-as your.package.name ls -al shared_prefs
-rw------- u0_a158  u0_a158       351 1970-01-17 16:54 your.package.name_preferences.xml

In order to back this file up, you must specify it as follows, including the .xml at the end.

Update your manifest:

<manifest ...
    <application ...
        android:fullBackupContent="@xml/backup">
    ....
</manifest>

And add res/xml/backup.xml:

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="sharedpref" path="your.package.name_preferences.xml"/>
</full-backup-content>

Note that you must include the .xml for all Shared Preferences file backups, even ones whose filename you've defined yourself - even though you don't include the .xml in the filename in code.

Community
  • 1
  • 1
Adam S
  • 16,144
  • 6
  • 54
  • 81
  • I found this article very helpful to go through the entire testing process: https://developer.android.com/guide/topics/data/testingbackup.html – alice_silver_man Dec 10 '16 at 05:39