Managed App Configuration For Android


Managed app configuration is a feature that gives IT admins the flexibility to remotely configure for work apps for different android users. previously known as application restrictions.

App Restriction Manager  :

   Application can define a logic which can be controlled by the App restriction Updates by it admins.

  • RestrictionsManager Controls the Scheme and structure for configuration
  • ACTION_APPLICATION_RESTRICTIONS_CHANGED  this broadcast notify application for new changes by it admins
  • Supports  [“bool” | “string” | “integer | “choice” | “multi-select” | “hidden | “bundle” | “bundle_array”]
  • Two level Nested structure is not Allowed for bundle_array  

Restriction Types :

  • Choice             Provide Radio button structure
  • Multi-select    Provide Checkbox Structure
  • Hidden             Provide Non UI structure for Default values
  • Bundle_array  Provide nested structure with bundle 


How to Configure in Android Application :

  • Create XMl File with your application structure (File name : app_restrictions.xml ) inside the res/xml folder.
  • key, title and restrictionType are mandatory.

If restrictionType is choice or multi-select , entries and entryValues are required

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">

    <restriction
   android:key="Home"
   android:restrictionType="bool"
   android:title="Show Page"
   android:description="Extra Details"
   android:defaultValue="App Home"
 />

 <restriction  <!-- For Multiple values structure for same structure  -->
   android:title="Allowed WebSites"
   android:description="Allowed Sites Listing"
   android:key="sites"
   android:restrictionType="bundle_array">

   <restriction
       android:title="Site"
       android:key="site"
       android:restrictionType="bundle">

       <restriction  
           android:title="URL"
           android:description="Add Your url"
           android:key="url"
           android:restrictionType="string"
           android:defaultValue="" />

 <restriction  <!-- Radio Button  -->
     android:description="Select Url type"
     android:entries="@array/url_types"
     android:entryValues="@array/url_types_values"
     android:key="url_types"
     android:restrictionType="choice"
     android:title="Url Type" />

<restriction  <!-- Check Box   -->
   android:title="Select days"
   android:description="you can select multiple days"
   android:entries="@array/entries_Days"
   android:entryValues="@array/entry_values_Days"
   android:key="days"
   android:restrictionType="multi-select"
 />


   </restriction>
   </restriction>
</restrictions>

Register to Android Manifest File

<application ... >

     <meta-data android:name="android.content.APP_RESTRICTIONS"
                   android:resource="@xml/app_restrictions" />
     ...
 </application>
  • How to Listen Changes in application :
  • RestrictionsManager manager = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE);
    <!– Restriction Manager for application —>
  • getApplicationRestrictions() provides current configuration data for application.and it should be used on application start only.
  • Bundle restrictions = manager.getApplicationRestrictions();

<!– New Data config for application →

  • restrictions containing a key-value pair for each configuration that has been set.

Use ACTION_APPLICATION_RESTRICTIONS_CHANGED broadcast to listen to new changes when your application is active.

Register Broadcast (Dynamic)

IntentFilter restrictionsFilter =
     newIntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);

BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() {
   @Override public void onReceive(Context context, Intent intent) {

       // Get the current configuration bundle
Bundle appRestrictions = manager.getApplicationRestrictions();

       // Application Function for data reading 
		getAllwebSites(appRestrictions);
		checkPageVisibility(appRestrictions);

   }
};

registerReceiver(restrictionsReceiver, restrictionsFilter); 
       // Register broadcast

How to Read Data in Android Application

Read Data for 

 <restriction
   android:key="Home"
   android:restrictionType="bool"
   android:title="Show Page"
   android:description="Extra Details"
   android:defaultValue="App Home"
 />


	Private void checkPageVisibility(Bundle appRestrictions){
		if (appRestrictions.containsKey("Home")) {

   Bool showHome=appRestrictions.getBoolean("Home");

	//your logic according to the value showHome
}
}

Read Data for Bundle array

 <restriction  <!-- For Multiple values structure for same structure  -->
   android:title="Allowed WebSites"
   android:description="Allowed Sites Listing"
   android:key="sites"
   android:restrictionType="bundle_array">

   <restriction
       android:title="Site"
       android:key="site"
       android:restrictionType="bundle">

       <restriction  
           android:title="URL"
           android:description="Add Your url"
           android:key="url"
           android:restrictionType="string"
           android:defaultValue="" />

 <restriction  <!-- Radio Button  -->
     android:description="Select Url type"
     android:entries="@array/url_types"
     android:entryValues="@array/url_types_values"
     android:key="url_types"
     android:restrictionType="choice"
     android:title="Url Type" />


Private void getAllwebSites(Bundle appRestrictions){

Parcelable[] parcelables = appRestrictions.getParcelableArray("sites");
   for (Parcelable parcelable : parcelables) {
Bundle current = (Bundle) parcelable;
       if (current.containsKey("url")) {
		print(“url ”+current.getString("url"))
}

if (current.containsKey("url_types")) {
		print(“types”+current.getString("url_types"))
}
}
}

Leave A Comment

Your email address will not be published. Required fields are marked *