0

I am trying to use android app restrictions. I have implemented the code and am trying to test it using Test DPC.

S I have set up a work profile (without a user) on my device using Test DPC. I added my application to the set of applications Test DPC manages. I can use Test DPC to retrieve the default values for my applications app restrictions. I can save any changes I make, there are no errors in Test DPC when I do this so I assume it is correct and it has saved them.

However I cannot read the app restrictions inside my application. It always returns an empty bundle.

Note - I am using Xamarin but the code should be similar to native Java.

I have added the following to my AndroidManiifest.xml

<application android:label="AppName" android:icon="@drawable/launchimage" android:theme="@style/Theme.actionbar_dark_style" android:logo="@drawable/applogo">
        <meta-data android:name="android.content.APP_RESTRICTIONS" android:resource="@xml/app_restrictions" />
    </application>

I am trying to access the application restrictions with the following code

    var restrictionsManager = (RestrictionsManager)Application.Context.GetSystemService(Context.RestrictionsService);
    Bundle appRestrictions = restrictionsManager.ApplicationRestrictions;

However the bundle returned is empty. Am I missing something? Does anyone have a working example?

Any help will be greatly appreciated.

rideintothesun
  • 1,628
  • 2
  • 12
  • 29

1 Answers1

1

I found out what the issue was. I use Test DPC to test the app restriction functionality. However when I try to debug my app, it was installing the app, and debugging the unmanaged version of the app, rather than the managed version. Once I tested it with the managed version of my app, I could access the application restrictions. So the lesson is that the app restrictions are only available if you app is being managed.

rideintothesun
  • 1,628
  • 2
  • 12
  • 29