If the SureMDM device administrator wants any third-party app to fetch a default device property or a custom property via SureMDM Agent, here is a way: using our SureMDM Agent API, the admin can establish an AIDL remote connection between the third-party apps and SureMDM Agent.
Using the SureMDM Agent API, third-party developers can seamlessly incorporate these APIs into their in-house applications, enabling them to retrieve or modify custom property values in the SureMDM console.
Purpose
The purpose of this knowledge article is to provide a guide on how to implement sharing or updating custom properties via third-party applications using the SureMDM Agent API.
Prerequisites
- As a prerequisite, the following action must be declared in the manifest of the third-party app:
<queries>
<package android:name=”com.nix” />
</queries>
Steps
Step 1: Follow the steps mentioned below to fetch the custom properties from an approved third-party app via SureMDM Agent.
The third-party app must be added to the Approved Apps list in the SureMDM Console so that custom properties can be fetched thereafter by means of an AIDL remote connection created between the third-party app and the SureMDM Agent.
To know more about how to approve third-party apps in the SureMDM console, refer to this article.
In an AIDL service connection, there are two apps involved, which act like a Client-Server pair.
In this case, the Client app would be the Third-Party app that wants to fetch data from or send data to the SureMDM Agent.
The SureMDM Agent serves as the Server/Host in this remote-service connection.
Step 2: Follow these steps to establish an AIDL service connection between the two apps.
In the client app:
- Create an AIDL file “IGears42SDK.aidl” in the “AIDL” folder.
NOTE: The AIDL file must be created under the package “com.nix” inside the AIDL directory.
Add the following code to the AIDL file:
package com.nix;
interface IGears42SDK {
String setProperty(String pStrKey, String pStrValue);
String getProperty(String pStrKey);
String getAllProperties();
}
Build the project or module at this stage after making the above changes to the AIDL file.
- Create a new class “SampleServiceConnection” that implements the ‘ServiceConnection’ interface from the android.content module.
In the SampleServiceConnection add the following code :
public class SampleServiceConn implements ServiceConnection {
private static IGears42SDK mIGears42Sdk;
public static IGears42SDK getIGears42SDK() {
return mIGears42Sdk;
}
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mIGears42Sdk = IGears42SDK.Stub.asInterface(iBinder);
Toast.makeText(CustomApplication.getAppContext(), "Connection established", Toast.LENGTH_SHORT).show();
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Toast.makeText(CustomApplication.getAppContext(), "Connection disconnected!", Toast.LENGTH_SHORT).show();
mIGears42Sdk = null;
}
}
In order to start using the AIDL remote connection we must first establish a connection between the client and the SureMDM Agent after the above changes are made.
Use the following code snippet to establish a remote connection between the client and the SureMDM Agent.
Intent intent = new Intent(IGears42SDK.class.getName());
intent.setPackage("com.nix");
intent.setAction("gears42.sdk");
intent.setClassName("com.nix", "com.nix.Gears42SDKService");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
getAppContext().bindService(intent, serviceConnection, Service.BIND_AUTO_CREATE);
Once the connection is established, we can use the getIGears42SDK method to access the custom property framework and GET (getAllProperties() or getProperty(key) ) or SET ( setProperty() ) the custom properties.
For Example :
IGears42SDK lObjIGears42Sdk = CustomPropertyServiceConn.getIGears42SDK();
if (lObjIGears42Sdk != null) {
//Get all properties
String allProperties = lObjIGears42Sdk.getAllProperties();
//Get the value of a specific “key” using
String propertyValue = lObjIGears42Sdk.getProperty(key);
//Update the value of a “key” to a new “value”
String status = lObjIGears42Sdk.setProperty(key, value);
}
5. The response format from the SureMDM Agent for different API calls :
- setProperty() : The user entered value for the corresponding key will be sent to the SureMDM Agent and an appropriate ‘String’ response will be returned to the client app.
- getProperty(String pStrKey) : The SureMDM Agent will return the value of the custom property key – ‘pStrKey’ or an appropriate message in case of failure of the operation.
- getAllProperties() : The SureMDM Agent will return all the custom properties stored locally with the device as a JSONArray String as mentioned in the below example or an appropriate message in case of any failure.
GET properties response example :
[{"dataType":"String","key":"test_1","value":"sample_val_1"},
{"dataType":"String","key":"test_2","value":"sample_val_2"}]
Need help?