How do you use getInt() with restrictions (managed configurations)?

129 views Asked by At

I have this in app_restrictions.xml:

<restriction
android:key="int1"
android:restrictionType="integer"
android:defaultValue="0"
/>

Now if I want to read it I get

> java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

I tried:

RestrictionsManager rm =     getApplicationContext().getSystemService(Context.RESTRICTIONS_SERVICE);
Integer val1 = rm.getApplicationRestrictions().getInt("int1");

I have no problem to read Booleans or Strings. Google doesn't provide examples for Integer. Is the interger restriction type usable at all? If so: how?

2

There are 2 answers

0
isthemartin On

The method: getApplicationRestrictions() returns a bundle. Probably your bundle is empty, if it is not, you have to navigate inside bundle (as a JsonObject) and get the value that you want.

0
The incredible Jan On

getInt() works as expected. The problem seems to be Test DPC. I didn't select the right type for a restriction of type choice in Test DPC. Choice isn't really supported in Test DPC. You have to type in a value and select it's type. Maybe integer values doesn't work at all for choice restrictions. I'll try with a real MDM system later...