Tech Blog

Android

Managed App Configuration For Android

By Devang kanzariya2 min read
← Back to blog

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"))
}
}
}

Keep reading

You may be interested in

Browse all articles →
Android Download file with Data URL
July 23, 20241 min read

Android Download file with Data URL

What is a Data URL? Data URLs are the type of URL scheme that is used to embed usually small types of files. In this URL, inline files are prefixed with the data: MIME type. data:[<mediatype>][;base64],<data> To download files having Data URLs inside Android: Firstly, we need to get an extension of the file from […]

By Bansari PanditRead More →
Download the file with blob URL in Android WebView
July 23, 20242 min read

Download the file with blob URL in Android WebView

What is the Blob URL? Blob URLs can only be generated by the browser with use of internal mapping and used within the current document while it’s open which means it is valid for the same session (ie. the life of the page/document). The blob URL looks like this: blob:http://example.com/550e8400-e29b-41d4-a716-446655440000 Below is the sample HTML […]

By Bansari PanditRead More →
Key Terminologies in Android Enterprise
December 20, 20227 min read

Key Terminologies in Android Enterprise

Android Enterprise is a Google-led initiative to enable the use of Android devices and applications in a workspace. This program offers APIs and tools for developers to integrate support of Android devices into the EMM (enterprise mobility management) or UEM (Unified Endpoint Management) solutions. The following are the key terms associated with Android Enterprise. This […]

By Sandeep KadamRead More →