Reputation: 857
I want to configure auto backup in my android app. The data hold by the app are too big (above 25MB) and I need to tell auto-backup mechanism to store only Shared Preferences data.
In AndroidManifest.xml, I added the line:
android:fullBackupContent="@xml/my_backup_rules"
and in this xml file I want to exclude data like file, external and root. The example code can looks like this:
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="root"
path=" ??? " />
</full-backup-content>
And I have no idea how to fill the path property. Also when excluding file or external. My app uses storage in external storage directory and I want to exclude it also. How should I define the path property?
Thanks in advance
Upvotes: 2
Views: 1378
Reputation: 41
If you want to exclude everything else simply do not use any exclude. As long there is no exclude used it will only use files from the included tags and exclude automatically everything else.
Additionally, just to store the SharedPreferences which comes build in from android:
lateinit var sharedPreferences: SharedPreferences
you can simply include:
For API 30 and lower:
<full-backup-content>
<include domain="sharedpref"/>
</full-backup-content>
For API 31+:
<data-extraction-rules>
<cloud-backup disableIfNoEncryptionCapabilities="false">
<include
domain="sharedpref"/>
</cloud-backup>
<device-transfer>
<include
domain="sharedpref"/>
</device-transfer>
</data-extraction-rules>
device-transfer (or short D2D) is used when user migrates his devices to a new devices. I added it here since it almost fulfils the same purpose.
Its nowhere clearly written in the Docs, which i spend now over 1 hours searching for, but you can add domains without path. Be aware people write that you can add path to include everything like.
path="."
which is utter nonsense? Please someone confirm. Never worked for me.
last but not least test everything. I found here a good guide: Test your Auto backup
Upvotes: 1
Reputation: 11
I don't know, but from https://developer.android.com/guide/topics/data/autobackup#IncludingFiles
By default, the system backs up almost all app data. For more information, see Files that are backed up. This section shows you how to define custom XML rules to control what gets backed up.
Specifies a file or folder to backup. By default, Auto Backup includes almost all app files. If you specify an element, the system no longer includes any files by default and backs up only the files specified. To include multiple files, use multiple elements.
So, you can use instead of . I think, this is better solution than you list excluded files.
Upvotes: 1