Android Management API (AMAPI) SDK टूल की मदद से, EMM की जानकारी वाले एक्सटेंशन ऐप्लिकेशन को सीधे Android Device Policy (एडीपी) के बारे में बताने और डिवाइस पर Commands
लागू करने की सुविधा मिलती है.
AMAPI SDK टूल के साथ इंटिग्रेट करने से, इस लाइब्रेरी के बारे में ज़्यादा जानकारी मिलती है. साथ ही, इससे आपको अपने ऐप्लिकेशन में इसे जोड़ने का तरीका भी पता चलता है.
SDK टूल के इंटिग्रेट होने के बाद, आपका एक्सटेंशन ऐप्लिकेशन, एडीपी के साथ इन बातों के लिए संपर्क कर सकता है:
- कमांड के अनुरोध भेजना
- ऑर्डर के अनुरोधों के स्टेटस के बारे में क्वेरी करना
- कमांड के स्टेटस में बदलाव पाना
समस्या से जुड़ा निर्देश
एक्सटेंशन ऐप्लिकेशन, ADP का इस्तेमाल करके जारी किए जाने वाले निर्देशों का अनुरोध कर सकता है.
IssueCommandRequest
में अनुरोध के लिए ऑब्जेक्ट शामिल है, जिसमें जारी किए जाने वाले निर्देश और खास पैरामीटर के बारे में जानकारी शामिल होगी.
नीचे दिए गए स्निपेट में, पैकेज के डेटा को मिटाने का अनुरोध करने का तरीका बताया गया है:
import android.util.Log;
...
import com.google.android.managementapi.commands.LocalCommandClientFactory;
import com.google.android.managementapi.commands.model.Command;
import com.google.android.managementapi.commands.model.GetCommandRequest;
import com.google.android.managementapi.commands.model.IssueCommandRequest;
import com.google.android.managementapi.commands.model.IssueCommandRequest.ClearAppsData;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
...
void issueClearAppDataCommand(ImmutableList<String> packageNames) {
Futures.addCallback(
LocalCommandClientFactory.create(getContext())
.issueCommand(createClearAppRequest(packageNames)),
new FutureCallback<Command>() {
@Override
public void onSuccess(Command result) {
// Process the returned command result here
Log.i(TAG, "Successfully issued command");
}
@Override
public void onFailure(Throwable t) {
Log.e(TAG, "Failed to issue command", t);
}
},
MoreExecutors.directExecutor());
}
IssueCommandRequest createClearAppRequest(ImmutableList<String> packageNames) {
return IssueCommandRequest.builder()
.setClearAppsData(
ClearAppsData.builder()
.setPackageNames(packageNames)
.build()
)
.build();
}
...
पहले के उदाहरण में, खास पैकेज के लिए ऐप्लिकेशन के डेटा को हटाने का साफ़ तौर पर अनुरोध किया गया है.
साथ ही, निर्देश मिलने तक इंतज़ार किया जा रहा है. अगर सही तरीके से जारी हो जाता है, तो Command
ऑब्जेक्ट को मौजूदा कमांड स्टेटस और कमांड आईडी के साथ दिखाया जाएगा. इसका इस्तेमाल, बाद में लंबे समय से चल रहे निर्देशों के स्टेटस के बारे में क्वेरी करने के लिए किया जा सकता है.
निर्देश पाएं
एक्सटेंशन ऐप्लिकेशन, पहले जारी किए गए निर्देश अनुरोधों की स्थिति के बारे में क्वेरी कर सकता है. किसी निर्देश का स्टेटस वापस पाने के लिए, आपको कमांड आईडी की ज़रूरत होगी. यह आईडी, समस्या से जुड़े निर्देश के लिए उपलब्ध होता है. नीचे दिए गए स्निपेट में, एडीपी पर GetCommandRequest
भेजने का तरीका बताया गया है.
import android.util.Log;
...
import com.google.android.managementapi.commands.LocalCommandClientFactory;
...
import com.google.android.managementapi.commands.model.GetCommandRequest;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
...
void getCommand(String commandId) {
Futures.addCallback(
LocalCommandClientFactory.create(getApplication())
.getCommand(GetCommandRequest.builder().setCommandId(commandId).build()),
new FutureCallback<Command>() {
@Override
public void onSuccess(Command result) {
// Process the returned command result here
Log.i(Constants.TAG, "Successfully issued command");
}
@Override
public void onFailure(Throwable t) {
Log.e(Constants.TAG, "Failed to issue command", t);
}
},
MoreExecutors.directExecutor());
}
...
निर्देश के स्टेटस में बदलाव करने वाले कॉलबैक सुनें
कोई एक्सटेंशन ऐप्लिकेशन, लंबे समय तक चलने वाले निर्देशों की स्थिति में होने वाले बदलावों के अपडेट पाने के लिए, कॉलबैक को रजिस्टर कर सकता है. इसके लिए, यह तरीका अपनाएं:
- कमांड के स्टेटस में होने वाले बदलावों की सूचना
CommandListener
को दी जाती है. इस इंटरफ़ेस को अपने ऐप्लिकेशन में लागू करें. साथ ही, जो स्टेटस अपडेट मिलते हैं उन्हें मैनेज करने का तरीका बताएं. NotificationReceiverService
को बड़ा करें औरCommandListener
इंस्टेंस दें.Android Management API की नीति में एक्सटेंडेड
NotificationReceiverService
की कैटगरी का नाम बताएं (नीति का कॉन्फ़िगरेशन देखें).import com.google.android.managementapi.commands.CommandListener; import com.google.android.managementapi.notification.NotificationReceiverService; ... public class SampleCommandService extends NotificationReceiverService { @Override protected void setupInjection() { // (Optional) If using DI and needs initialisation then use this method. } @Override public CommandListener getCommandListener() { // return the concrete implementation from previous step return ...; } }
सेवा को अपने
AndroidManifest.xml
में जोड़ें और पक्का करें कि उसे एक्सपोर्ट कर दिया गया हो.<service android:name = ".notification.SampleCommandService" android:exported = "true" />
नीति से जुड़ा कॉन्फ़िगरेशन
एक्सटेंशन ऐप्लिकेशन, सीधे एडीपी के साथ संपर्क कर सके, इसके लिए ईएमएम को
extensionConfig
नीति देनी होगी.
"applications": [{
"packageName": "com.amapi.extensibility.demo",
...
"extensionConfig": {
"signingKeyFingerprintsSha256": [
// Include signing key of extension app
],
// Optional if callback is implemented
"notificationReceiver": "com.amapi.extensibility.demo.notification.SampleCommandService"
}
}]
टेस्ट करना
यूनिट टेस्टिंग
LocalCommandClient
एक इंटरफ़ेस है. इसकी मदद से, टेस्ट किया जा सकने वाला
लागू किया जा सकता है.
इंटिग्रेशन की जांच करना
एडीपी के साथ टेस्ट करने के लिए, यहां दी गई जानकारी की ज़रूरत होगी:
- एक्सटेंशन ऐप्लिकेशन का पैकेज नाम.
- ऐप्लिकेशन पैकेज से जुड़े हस्ताक्षर का हेक्स-एन्कोडेड SHA-256 हैश.
- वैकल्पिक रूप से, अगर कॉलबैक की जांच की जा रही है - कॉलबैक की सुविधा देने के लिए, हाल ही में शुरू की गई सेवा
की सेवा का पूरी तरह क्वालिफ़ाइड नाम. (उदाहरण में,
CommandService
का पूरी तरह क्वालिफ़ाइड नाम).