Restricted profiles settings not being remembered

2019-07-04 09:05发布

问题:

I have followed http://www.youtube.com/watch?v=pdUcANNm72o and set up settings for my app.

I have 10 Booleans that appear. This can be set and when in the profile called.

However they are not ticked/unticked then the owner goes back into the settings, they have reverted back to default.

1/ Is the system meant to know which user has which settings already selected or am I meant to tick or un tick in the GetRestrictionsReceiver. If I am, how am I meant to see each users settings as the

       Bundle restrictionsBundle = ((UserManager) getSystemService(Context.USER_SERVICE)).getApplicationRestrictions(getPackageName());
        restrictionsBundle.getBoolean("....

is for when the user is logged on!?

2/ Is this a bug?

Thanks in advance.

回答1:

Turns out that you need to add some code when generating the RestrictionEntry

Though I will update so that people don't have to hunt...

In your receiver call

        final Bundle oldRestrictions = intent.getBundleExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE);

then when creating the entry reference it.

e.g.

RestrictionEntry myEntry = new RestrictionEntry(KEY, oldRestrictions.getBoolean(KEY, false)); 
myEntry.setType(RestrictionEntry.TYPE_BOOLEAN);
myEntry.setTitle("KEY TITLE");
newEntries.add(myEntry);