harmony 鸿蒙@ohos.enterprise.bluetoothManager (Bluetooth Management)
@ohos.enterprise.bluetoothManager (Bluetooth Management)
The bluetoothManager module provides Bluetooth management capabilities, including setting and obtaining Bluetooth information.
NOTE
The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The APIs of this module can be used only in the stage model.
The APIs of this module can be called only by a device administrator application that is enabled.
The global restriction policies are provided by restrictions. To disable Bluetooth globally, see @ohos.enterprise.restrictions.
Modules to Import
import { bluetoothManager } from '@kit.MDMKit';
bluetoothManager.getBluetoothInfo
getBluetoothInfo(admin: Want): BluetoothInfo
Obtains device Bluetooth information.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
Return value
Type | Description |
---|---|
BluetoothInfo | Bluetooth information, including the Bluetooth name, state, and profile connection state. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
import { bluetoothManager } from '@kit.MDMKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let result: bluetoothManager.BluetoothInfo = bluetoothManager.getBluetoothInfo(wantTemp);
console.info(`Succeeded in getting bluetooth info: ${JSON.stringify(result)}`);
} catch(err) {
console.error(`Failed to get bluetooth info. Code: ${err.code}, message: ${err.message}`);
}
bluetoothManager.addAllowedBluetoothDevices
addAllowedBluetoothDevices(admin: Want, deviceIds: Array<string>): void
Adds allowed Bluetooth devices. This API should be called before setDisallowedPolicy, so that Bluetooth can be successfully disabled. Otherwise, a conflict occurs.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
deviceIds | Array<string> | Yes | MAC addresses of the Bluetooth devices to add. This array can hold a maximum of 1000 MAC addresses. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
9200010 | A conflict policy has been configured. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
import { bluetoothManager } from '@kit.MDMKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"];
try {
bluetoothManager.addAllowedBluetoothDevices(wantTemp,deviceIds);
console.info(`Succeeded in adding allowed bluetooth devices.`);
} catch(err) {
console.error(`Failed to add allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
}
bluetoothManager.removeAllowedBluetoothDevices
removeAllowedBluetoothDevices(admin: Want, deviceIds: Array<string>): void
Removes allowed Bluetooth devices.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
deviceIds | Array<string> | Yes | MAC addresses of the Bluetooth devices to remove. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
import { bluetoothManager } from '@kit.MDMKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"];
try {
bluetoothManager.removeAllowedBluetoothDevices(wantTemp,deviceIds);
console.info(`Succeeded in removing allowed bluetooth devices.`);
} catch(err) {
console.error(`Failed to remove allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
}
bluetoothManager.getAllowedBluetoothDevices
getAllowedBluetoothDevices(admin: Want): Array<string>
Obtains allowed Bluetooth devices.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
Return value
Type | Description |
---|---|
Array<string> | MAC addresses of allowed Bluetooth devices obtained. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
import { bluetoothManager } from '@kit.MDMKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let result: Array<string> = bluetoothManager.getAllowedBluetoothDevices(wantTemp);
console.info(`Succeeded in getting allowed bluetooth devices. Result: ${JSON.stringify(result)}`);
} catch(err) {
console.error(`Failed to get allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
}
BluetoothInfo
Represents the device Bluetooth information.
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Model restriction: This API can be used only in the stage model.
Name | Type | Mandatory | Description |
---|---|---|---|
name | string | Yes | Bluetooth name of the device. |
state | access.BluetoothState | Yes | Bluetooth state of the device. |
connectionState | constant.ProfileConnectionState | Yes | Bluetooth profile connection state of the device. |
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Enterprise Device Management Error Codes
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
harmony 鸿蒙@ohos.enterprise.accountManager (Account Management) (System API)
harmony 鸿蒙@ohos.enterprise.accountManager (Account Management)
harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management) (System API)
harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management)
harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management (System API)
harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management)
harmony 鸿蒙@ohos.enterprise.bluetoothManager (Bluetooth Management) (System API)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦