Exclude specific shared key with Android 6.0 startup

I implemented the "old" GCM implementation, where the example code had the following:

public static final String PROPERTY_REG_ID = "registration_id"; private SharedPreferences getGCMPreferences(Context context) { return context.getSharedPreferences(SampleApp.class.getSimpleName(), Context.MODE_PRIVATE); } ... String registrationId = prefs.getString(PROPERTY_REG_ID, ""); 

With the new backup system in Android 6.0 it says that you should exclude this key, but exclude format documents: http://developer.android.com/training/backup/autosyncapi.html

doesn't actually indicate how you can exclude sharedpreference, except that:

sharedpref: indicates a SharedPreferences object that returns the getSharedPreferences () method.

Is there no getSharedPreferences () without any parameters that I know of?

I tried:

 <?xml version="1.0" encoding="utf-8"?> <full-backup-content> <exclude domain="sharedpref" path="registration_id"/> </full-backup-content> 

But this does not seem to work fine, since I did not indicate which sharedpreference file it should exclude. Has anyone successfully implemented this?

+7
android-6.0-marshmallow android-backup-service
source share
1 answer

The exception is the general preference file, not one key in the file.

(In your example, your file name is obtained through SampleApp.class.getSimpleName() .)

As noted in the commentary, you need to specify the full file name, so be sure to specify the file extension “.xml” when you put this name in the exclude command.

+9
source share

All Articles