Quickstart

This page shows you how to get started with the Android Management API. Follow the steps below and use APIs explorer to enroll an enterprise, create a policy, and provision a device.

In order to use this quickstart guide, you need:

  • A new or factory reset Android 6.0+ device.
  • A Gmail account. This account cannot be associated with an existing enterprise.
  • To select or create a Cloud Platform project that you own or can edit. Take note of the project ID.
    Go to the Projects Page

Generate a sign-up URL

Before you can create an enterprise, you first need to generate a sign-up URL by calling signupUrls.create. Use the button below to send the request using the APIs Explorer. Ensure the following parameters are specified:

  • callbackUrl: Any https URL (for example, https://localhost).
  • projectId: Your project ID.

Try It!

A successful response looks like:

{
  "name": "signupUrls/C50995d7da019b1d0",
  "url": "https://play.google.com/work/adminsignup?token=SAH2pBTtEfOwJEVStsu8"
}

The response contains the name of the sign-up URL in the form of signupUrls/{name} and a url. Take note of the name and visit the URL.

Complete the sign-up flow

Enterprise sign up
Figure 1. Enterprise sign-up page

Sign in with a Gmail account to register a new enterprise. After you sign in, click Complete sign up. You're redirected to the callbackUrl you specified in the previous section.

https://localhost/?enterpriseToken=example-enterprise-token

Take note of the enterpriseToken appended to your callback URL.

Create an enterprise

To create an enterprise, call enterprises.create. Use the button below to send the request using the APIs Explorer. Ensure the following parameters are specified:

  • enterpriseToken: The enterpriseToken retrieved in the previous section.
  • projectId: Your project ID.
  • signupUrlName: The name retrieved when generating a sign-up URL.
  • In the request body, add the appAutoApprovalEnabled property and check its box. This ensures that any apps you install with your policy are automatically approved for your enterprise.

Try It!

A successful response looks like:

{
  "name": "enterprises/{enterprise-id}",
  "appAutoApprovalEnabled": true
}

The response contains the name of the newly created enterprise in the form of enterprises/{enterprise_id}. Take note of the name.

Create a policy

Call enterprises.policies.patch to create a policy. Use the button below to send the request using the APIs Explorer. Ensure the following parameters are specified:

  • name: Name of the policy in the form enterprises/{enterprise_id}/policies/{policy_id}. The {policy_id} can be any string of your choice.
  • Patch body: Use the provided policy or create your own. For a full list of policy options, see the API reference.
    {
      "adjustVolumeDisabled": true,
      "applications":
        [
          {
            "installType": "FORCE_INSTALLED",
            "packageName": "com.google.android.apps.maps"
          }
        ]
    }
    

Try It!

A successful response looks like:

{
  "name": "enterprises/{enterprise-id}/policies/default",
  "version": "3",
  "applications": [
   {
    "packageName": "com.google.android.apps.maps",
    "installType": "FORCE_INSTALLED"
   }
  ],
  "adjustVolumeDisabled": true
}

Create an enrollment token

To generate an enrollment token, call enterprises.enrollmentTokens.create. Use the button below to send the request using the APIs Explorer. Ensure the following parameters are specified:

  • parent: The enterprise name in the form of enterprises/{enterprise-id}.
  • Request body: Set policyName to the name of the policy that you created.

Try It!

A successful response looks like:

{
  "name": "enterprises/{enterprise-id}/enrollmentTokens/{enrollment-token-id}",
  "value": "{enrollment-token}",
  "expirationTimestamp": "2017-07-19T11:25:56.208Z",
  "policyName": "{your-policy-name}",
  "qrCode": "{\"android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME\":\"com.google.android.apps.work.clouddpc/.receivers.CloudDeviceAdminReceiver\",
  \"android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM\":\"I5YvS0O5hXY46mb01BlRjq4oJJGs2kuUcHvVkAPEXlg\",
  \"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION\":\"https://play.google.com/managed/downloadManagingApp?identifier=setup\",
  \"android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE\":{\"com.google.android.apps.work.clouddpc.EXTRA_ENROLLMENT_TOKEN\":\"{enrollment-token}\"}}"
}

The value field in the response contains the enrollment token. You can provision a device by entering the enrollment token manually or by scanning a QR code containing the token and other provisioning settings. The token expires after one hour by default. To change the expiration period, set duration to a different value.

Generate a QR code

For testing, you can use an online QR code generator to convert the qrcode string returned in the response into a QR code. When pasting the string, make sure to remove all escape '\' characters. There are numerous QR code generators available online, including Zxing. To use Zxing:

  1. Select Text from the Contents dropdown menu.
  2. Paste the qrcode into the Text content field. Remember to remove all escape '\' characters from the string.
  3. Click Generate to generate the QR code.

Provision a device

For Android 7.0+ devices

  1. Turn on a new or factory-reset device.
  2. Tap the same spot on the welcome screen six times to enter QR code mode.
  3. Enter your Wi-Fi details.
  4. Scan the QR code that you generated. The device is now set up with Android Management.

For Android 6.0+ devices

  1. Turn on a new or factory-reset device.
  2. Follow the setup wizard and enter your Wi-Fi details.
  3. When prompted to sign in, enter afw#setup.
  4. Tap Next, and then accept the installation of Android Device Policy.
  5. Scan the QR code that you generated or enter the enrollment token manually. The device is now set up with Android Management.

Next steps

Cleanup (optional)

1. Deprovision a device

Before you can deprovision a device, you need the device's deviceId. To get a list of all your provisioned devices, call enterprises.devices.list. Use the button below to send the request using the APIs Explorer. Ensure the following parameter is specified:

  • parent: The enterprise name in the form of enterprises/{enterprise-id}.

Try It!

A successful response contains an array of devices resources. Because you only need the name field to deprovision a device, the example response below is shortened.

{
  "devices": [
    {
      "name": "enterprises/{enterprise-id}/devices/{device-id}",
      "state": "ACTIVE",
      // Additional device resource fields
    }
  ]
}

Call enterprises.devices.delete to deprovision and factory-reset a device. Use the button below to send the request using the APIs Explorer. Ensure the following parameter is specified:

  • name: The device ID in the form of enterprises/{enterprise-id}/devices/{device-id}.

Try It!

If successful, the request returns an empty response body.

2. Delete an enterprise

You can only associate your Gmail account with a single enterprise. To unbind your account from an enterprise, you need to delete the enterprise:

  1. Visit play.google.com/work with the account used to create the enterprise.
  2. Select Admin Settings.
  3. In Organization information, select the three vertical dots.
  4. Click Delete Organization.

You can now use your Gmail account to create another enterprise.

Additional reading

For more detailed information on how to develop an Android management solution, review the Introduction, Developer's guide, and API reference

Start developing

发送以下问题的反馈:

此网页
Android Management API (beta)
Android Management API (beta)