Search code examples
androidandroid-bluetoothandroid-management-api

Enable bluetooth with Android Management API


I have noticed that some devices have bluetooth enabled by default (after a factory reset) and some others don't.

In my Android Management API policy I would like to specify that bluetooth should be enabled.

I've tried setting bluetoothDisabled to false but it doesn't have any effect: after provisioning the device bluetooth's status is the default one.

How can I force bluetooth to be enabled with Android Management API ?


Solution

  • The Android Management API doesn't offer to enable/disable Bluetooth directly at the moment.

    However you can implement a companion app that controls the Bluetooth state through BluetoothAdapter enable() and disable() methods. To do so:

    1. Create an Android app (the "companion" app) and upload it to Play (possibly as a private app)
    2. Set a policy to force install this app, grant it all permissions (so it gets the permission android.permission.BLUETOOTH_ADMIN) and launch it during setup:
    {
      "applications": [
        {
          "packageName": "com.example.companion",
          "installType": "REQUIRE_FOR_SETUP",
          "defaultPermissionPolicy": "GRANT"
        }
      ],
      "setupActions":[
          {
             "launchApp":{
                "packageName":"com.example.companion"
             }
          }
       ]
    }
    
    1. When the companion app launches call BluetoothAdapter enable() or disable() as needed
    2. (Optional) Implement managed configurations in the companion app to be able to configure it from the Android Management API via ApplicationPolicy.managedConfiguration.

    You can also use the companion app for additional purposes if needed. Common use cases include: status page for your service, debug interface for admins, etc.