تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح حزمة تطوير البرامج (SDK) لواجهة برمجة التطبيقات Android Management API (AMAPI) لتطبيق إضافة محدّد من إدارة الخدمات الجوّالة للمؤسسات (EMM)
التواصل مباشرةً مع تطبيق Android Device Policy (ADP) وتنفيذ Commands
على الجهاز.
يمكن لتطبيق إضافة طلب إصدار أوامر باستخدام ADP.
يحتوي IssueCommandRequest على عنصر الطلب الذي سيحتوي على تفاصيل عن
الأمر الذي سيتم إصداره ومعلمات محدّدة.
يوضّح المقتطف التالي كيفية إصدار طلب لمحو بيانات الحزمة:
importandroid.util.Log;...importcom.google.android.managementapi.commands.LocalCommandClientFactory;importcom.google.android.managementapi.commands.model.Command;importcom.google.android.managementapi.commands.model.GetCommandRequest;importcom.google.android.managementapi.commands.model.IssueCommandRequest;importcom.google.android.managementapi.commands.model.IssueCommandRequest.ClearAppsData;importcom.google.common.collect.ImmutableList;importcom.google.common.util.concurrent.FutureCallback;importcom.google.common.util.concurrent.Futures;importcom.google.common.util.concurrent.MoreExecutors;...voidissueClearAppDataCommand(ImmutableList<String>packageNames){Futures.addCallback(LocalCommandClientFactory.create(getContext()).issueCommand(createClearAppRequest(packageNames)),newFutureCallback<Command>(){@OverridepublicvoidonSuccess(Commandresult){// Process the returned command result hereLog.i(TAG,"Successfully issued command");}@OverridepublicvoidonFailure(Throwablet){Log.e(TAG,"Failed to issue command",t);}},MoreExecutors.directExecutor());}IssueCommandRequestcreateClearAppRequest(ImmutableList<String>packageNames){returnIssueCommandRequest.builder().setClearAppsData(ClearAppsData.builder().setPackageNames(packageNames).build()).build();}...
يوضّح المثال السابق إصدار طلب واضح لبيانات التطبيق لحزمات
محدّدة والانتظار إلى أن يتم إصدار الأمر بنجاح. في حال
إصداره بنجاح، سيتم عرض عنصر Command يتضمّن الحالة الراهنة
للأمر ورقم تعريفه الذي يمكن استخدامه لاحقًا للاستعلام عن حالة
أي أوامر تستغرق وقتًا طويلاً في التنفيذ.
الحصول على الأمر
يمكن لتطبيق الإضافة الاستعلام عن حالة طلبات الأوامر التي تم إصدارها سابقًا. ل retrieving a command's status، ستحتاج إلى معرّف الأمر (متاح من
طلب إصدار الأمر). يوضّح المقتطف التالي كيفية إرسال ملف
GetCommandRequest إلى ADP.
importandroid.util.Log;...importcom.google.android.managementapi.commands.LocalCommandClientFactory;...importcom.google.android.managementapi.commands.model.GetCommandRequest;importcom.google.common.util.concurrent.FutureCallback;importcom.google.common.util.concurrent.Futures;importcom.google.common.util.concurrent.MoreExecutors;...voidgetCommand(StringcommandId){Futures.addCallback(LocalCommandClientFactory.create(getApplication()).getCommand(GetCommandRequest.builder().setCommandId(commandId).build()),newFutureCallback<Command>(){@OverridepublicvoidonSuccess(Commandresult){// Process the returned command result hereLog.i(Constants.TAG,"Successfully issued command");}@OverridepublicvoidonFailure(Throwablet){Log.e(Constants.TAG,"Failed to issue command",t);}},MoreExecutors.directExecutor());}...
الاستماع إلى عمليات الاستدعاء المتعلّقة بتغيير حالة الطلب
يمكن لتطبيق إضافة تسجيل مكالمة اختياريًا لتلقّي آخر المعلومات المتعلّقة
بتغييرات حالة الأوامر التي تستغرق وقتًا طويلاً باتّباع الخطوات التالية:
يتم إرسال إشعارات إلى CommandListener بشأن التغييرات في حالة الأوامر، ويجب تنفيذ هذه
الواجهة في تطبيقك وتقديم معلومات عن كيفية التعامل مع
آخر المعلومات الواردة حول الحالة.
حدِّد اسم فئة NotificationReceiverService الموسّعة في سياسة واجهة برمجة التطبيقات
لإدارة Android (راجِع إعداد السياسة).
importcom.google.android.managementapi.commands.CommandListener;importcom.google.android.managementapi.notification.NotificationReceiverService;...publicclassSampleCommandServiceextendsNotificationReceiverService{@OverridepublicCommandListenergetCommandListener(){// return the concrete implementation from previous stepreturn...;}}
ضبط السياسة
لتفعيل تطبيق الإضافة للتواصل مباشرةً مع ADP، على خدمة إدارة الخدمات الجوّالة (EMM)
توفير سياسة 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 هي واجهة، وبالتالي تسمح بتوفير تنفيذ قابل للتحقّق منه.
اختياريًا، في حال اختبار طلب معاودة الاتصال، اسم مؤهَّل بالكامل للخدمة من
الخدمة التي تم طرحها حديثًا لتفعيل طلب معاودة الاتصال. (الاسم المؤهّل بالكامل ل
CommandService في المثال)
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Android Management API (AMAPI) SDK enables extension apps to communicate directly with Android Device Policy (ADP) to execute commands on the device.\u003c/p\u003e\n"],["\u003cp\u003eThe SDK currently supports the \u003ccode\u003eClearAppData\u003c/code\u003e command, which allows for the clearing of specified app data.\u003c/p\u003e\n"],["\u003cp\u003eExtension apps can issue command requests to ADP, query the status of these requests, and receive updates on status changes through callbacks.\u003c/p\u003e\n"],["\u003cp\u003eTo enable communication between the extension app and ADP, the EMM must provide an \u003ccode\u003eextensionConfig\u003c/code\u003e policy that includes the extension app's package name, signing key fingerprint, and optionally, a notification receiver service.\u003c/p\u003e\n"],["\u003cp\u003eTesting can be achieved through unit testing with the \u003ccode\u003eLocalCommandClient\u003c/code\u003e interface, or through integration testing, using the package name, SHA-256 hash, and notification service.\u003c/p\u003e\n"]]],["The Android Management API (AMAPI) SDK allows an extension app to interact with Android Device Policy (ADP). It enables sending command requests, querying their status, and receiving status change callbacks. The SDK supports the `ClearAppData` command to clear specified apps' data. To issue a command, `IssueCommandRequest` is used, and the status can be retrieved with `GetCommandRequest`, providing a Command Id. The `CommandListener` interface and `NotificationReceiverService` class allow the app to receive updates on status changes. The `extensionConfig` policy, specified by an EMM, enables this communication.\n"],null,["# Extension apps and local commands\n\nThe Android Management API (AMAPI) SDK enables an EMM-specified extension app to\ncommunicate directly with Android Device Policy (ADP) and execute [`Commands`](/android/management/reference/amapi/com/google/android/managementapi/commands/package-summary)\non the device.\n| **Note:** Only the [`ClearAppData`](/android/management/reference/rest/v1/enterprises.devices/issueCommand#CommandType.ENUM_VALUES.CLEAR_APP_DATA) command is supported.\n\n[Integrate with the AMAPI SDK](/android/management/sdk-integration) provides more information about\nthis library and how to add it to your application.\n\nOnce integrated the SDK, your extension app can communicate with ADP to:\n\n- [send command requests](#issue_command)\n- [query the status of command requests](#get_command)\n- [receive command status changes](#listen_to_callbacks)\n\nIssue Command\n-------------\n\nAn extension app can request for commands to be issued using ADP.\n[`IssueCommandRequest`](/android/management/reference/amapi/com/google/android/managementapi/commands/model/IssueCommandRequest) contains the request object that will contain detail on\nthe command to be issued and specific parameters.\n\nThe following snippet shows how to issue a request to clear the package's data: \n\n import android.util.Log;\n ...\n import com.google.android.managementapi.commands.LocalCommandClientFactory;\n import com.google.android.managementapi.commands.model.Command;\n import com.google.android.managementapi.commands.model.GetCommandRequest;\n import com.google.android.managementapi.commands.model.IssueCommandRequest;\n import com.google.android.managementapi.commands.model.IssueCommandRequest.ClearAppsData;\n import com.google.common.collect.ImmutableList;\n import com.google.common.util.concurrent.FutureCallback;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.MoreExecutors;\n\n ...\n void issueClearAppDataCommand(ImmutableList\u003cString\u003e packageNames) {\n Futures.addCallback(\n LocalCommandClientFactory.create(getContext())\n .issueCommand(createClearAppRequest(packageNames)),\n new FutureCallback\u003cCommand\u003e() {\n @Override\n public void onSuccess(Command result) {\n // Process the returned command result here\n Log.i(TAG, \"Successfully issued command\");\n }\n\n @Override\n public void onFailure(Throwable t) {\n Log.e(TAG, \"Failed to issue command\", t);\n }\n },\n MoreExecutors.directExecutor());\n }\n\n IssueCommandRequest createClearAppRequest(ImmutableList\u003cString\u003e packageNames) {\n return IssueCommandRequest.builder()\n .setClearAppsData(\n ClearAppsData.builder()\n .setPackageNames(packageNames)\n .build()\n )\n .build();\n }\n ...\n\nThe earlier example shows issuing a clear app data request for specified\npackages and waiting until the command has been successfully issued. If\nsuccessfully issued, a `Command` object will be returned with the current\ncommand status and the command ID which can later be used to query the status of\nany long running commands.\n\nGet Command\n-----------\n\nAn extension app can query the status of previously issued command requests. To\nretrieve a command's status, you will need the command ID (available from the\nissue command request). The following snippet shows how to send a\n[`GetCommandRequest`](/android/management/reference/amapi/com/google/android/managementapi/commands/model/GetCommandRequest) to ADP. \n\n import android.util.Log;\n ...\n import com.google.android.managementapi.commands.LocalCommandClientFactory;\n ...\n import com.google.android.managementapi.commands.model.GetCommandRequest;\n import com.google.common.util.concurrent.FutureCallback;\n import com.google.common.util.concurrent.Futures;\n import com.google.common.util.concurrent.MoreExecutors;\n\n ...\n void getCommand(String commandId) {\n Futures.addCallback(\n LocalCommandClientFactory.create(getApplication())\n .getCommand(GetCommandRequest.builder().setCommandId(commandId).build()),\n new FutureCallback\u003cCommand\u003e() {\n @Override\n public void onSuccess(Command result) {\n // Process the returned command result here\n Log.i(Constants.TAG, \"Successfully issued command\");\n }\n\n @Override\n public void onFailure(Throwable t) {\n Log.e(Constants.TAG, \"Failed to issue command\", t);\n }\n },\n MoreExecutors.directExecutor());\n }\n ...\n\nListen to Command status change callbacks\n-----------------------------------------\n\nAn extension app can optionally register a callback to receive updates for\nstatus changes of long running commands following these steps:\n\n1. Command status changes are notified to [`CommandListener`](/android/management/reference/amapi/com/google/android/managementapi/commands/CommandListener), implement this interface in your app and provide implementation on how to handle the received status updates.\n2. Extend [`NotificationReceiverService`](/android/management/sdk-integration#notification_receiver_service) and provide a `CommandListener` instance through the `getCommandListener` method.\n3. Specify class name of extended `NotificationReceiverService` in the Android\n Management API policy ([see Policy Configuration](#policy)).\n\n import com.google.android.managementapi.commands.CommandListener;\n import com.google.android.managementapi.notification.NotificationReceiverService;\n\n ...\n\n public class SampleCommandService extends NotificationReceiverService {\n\n @Override\n public CommandListener getCommandListener() {\n // return the concrete implementation from previous step\n return ...;\n }\n }\n\nPolicy Configuration\n--------------------\n\nTo enable the extension app to communicate directly with ADP, the EMM has to\nprovide an [`extensionConfig`](/android/management/reference/rest/v1/enterprises.policies#ExtensionConfig) policy. \n\n \"applications\": [{\n \"packageName\": \"com.amapi.extensibility.demo\",\n ...\n \"extensionConfig\": {\n \"signingKeyFingerprintsSha256\": [\n // Include signing key of extension app\n ],\n // Optional if callback is implemented\n \"notificationReceiver\": \"com.amapi.extensibility.demo.notification.SampleCommandService\"\n }\n }]\n\n### Testing\n\n#### Unit testing\n\n[`LocalCommandClient`](/android/management/reference/amapi/com/google/android/managementapi/commands/LocalCommandClient) is an interface and thus allows to provide a testable\nimplementation.\n\n#### Integration testing\n\nThe following information will be needed to test with ADP:\n\n1. Package name of the extension app.\n2. The hex-encoded SHA-256 hash of the Signature associated with the app package.\n3. Optionally, if testing callback - fully qualified name of the service from the newly introduced service to support callback. (Fully qualified name of `CommandService` in the example)."]]