App Config sample codes¶
In order to use the MDM feature called Application Configuration (aka "App Config"), your business application needs to implement a few things in order to receive the configuration sent by the MDM.
Notification¶
The Famoco Layer agent notifies the business application when a new configuration is available using the
com.famoco.intent.action.CONFIG_CHANGED
broadcast intent:
<receiver android:name=".ConfigReceiver">
<intent-filter>
<action android:name="com.famoco.intent.action.CONFIG_CHANGED" />
</intent-filter>
</receiver>
Configuration retrieval¶
Once the business application has been notified about the new configuration, it has to retrieve it using AIDL. The interface is defined as follows:
// IAppConfig.aidl
package com.famoco.fms;
interface IAppConfig {
// Retrieve a raw string containing the configuration in UTF-8 decoded from the base64 provided by the MDM
String getConfig();
}
The following code can be used in the business application to bind to the service and retrieve the configuration:
var intent = Intent().setClassName("com.famoco.fms", "com.famoco.fms.services.appconfig.AppConfigDispatcherService")
var mServiceConn: ServiceConnection = object : ServiceConnection {
override fun onServiceDisconnected(name: ComponentName?) {
mService = null
}
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
mService = IAppConfig.Stub.asInterface(service)
Log.d(TAG, "config: ${mService?.config}")
}
}
bindService(intent, mServiceConn, Service.BIND_AUTO_CREATE)