使用 Android 管理 API 启用蓝牙
Enable bluetooth with Android Management API
我注意到有些设备默认启用蓝牙(恢复出厂设置后),而有些则没有。
在我的 Android Management API policy 中,我想指定应启用蓝牙。
我试过将 bluetoothDisabled 设置为 false
但它没有任何效果:配置设备后蓝牙的状态是默认状态。
如何使用 Android Management API 强制启用蓝牙?
Android 管理 API 目前不直接提供给 enable/disable 蓝牙。
不过,您可以通过 BluetoothAdapter
enable()
和 disable()
方法实现控制蓝牙状态的配套应用。为此:
- 创建一个 Android 应用程序("companion" 应用程序)并将其上传到 Play(可能是 private app)
- 设置强制安装此应用程序的策略,授予它所有权限(因此它获得权限
android.permission.BLUETOOTH_ADMIN
)和launch it during setup:
{
"applications": [
{
"packageName": "com.example.companion",
"installType": "REQUIRE_FOR_SETUP",
"defaultPermissionPolicy": "GRANT"
}
],
"setupActions":[
{
"launchApp":{
"packageName":"com.example.companion"
}
}
]
}
- 当配套应用启动时,根据需要调用
BluetoothAdapter
enable()
或 disable()
- (可选)实施 managed configurations in the companion app to be able to configure it from the Android Management API via
ApplicationPolicy.managedConfiguration
.
如果需要,您还可以将配套应用用于其他目的。常见用例包括:服务的状态页面、管理员的调试界面等。
我注意到有些设备默认启用蓝牙(恢复出厂设置后),而有些则没有。
在我的 Android Management API policy 中,我想指定应启用蓝牙。
我试过将 bluetoothDisabled 设置为 false
但它没有任何效果:配置设备后蓝牙的状态是默认状态。
如何使用 Android Management API 强制启用蓝牙?
Android 管理 API 目前不直接提供给 enable/disable 蓝牙。
不过,您可以通过 BluetoothAdapter
enable()
和 disable()
方法实现控制蓝牙状态的配套应用。为此:
- 创建一个 Android 应用程序("companion" 应用程序)并将其上传到 Play(可能是 private app)
- 设置强制安装此应用程序的策略,授予它所有权限(因此它获得权限
android.permission.BLUETOOTH_ADMIN
)和launch it during setup:
{
"applications": [
{
"packageName": "com.example.companion",
"installType": "REQUIRE_FOR_SETUP",
"defaultPermissionPolicy": "GRANT"
}
],
"setupActions":[
{
"launchApp":{
"packageName":"com.example.companion"
}
}
]
}
- 当配套应用启动时,根据需要调用
BluetoothAdapter
enable()
或disable()
- (可选)实施 managed configurations in the companion app to be able to configure it from the Android Management API via
ApplicationPolicy.managedConfiguration
.
如果需要,您还可以将配套应用用于其他目的。常见用例包括:服务的状态页面、管理员的调试界面等。