0

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
The incredible Jan
  • 741
  • 10
  • 17
  • 1
    Try defaultValue=0 without the quotes – Gabe Sechan Jul 01 '19 at 13:35
  • @Gabe Sechan That doesn't work. The XML is not well-formed then and Android resource compilation fails. – The incredible Jan Jul 01 '19 at 13:40
  • Not ideal but can't you set restrictionType to string then parse it to int in your code? – steven35 Jul 01 '19 at 14:49
  • @steven35 This is what I have done now but a definitive answer would be great if getInt() isn't usable for reading integer restrictions. Then the question would be why Google uses bundle for restriction data if you can't use all of it's methods. And Google's documentations su... are not good. – The incredible Jan Jul 02 '19 at 05:36

2 Answers2

0

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...

The incredible Jan
  • 741
  • 10
  • 17
0

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.