导入模块
import { usbManager } from '@kit.MDMKit';
usbManager.addAllowedUsbDevices
addAllowedUsbDevices(admin: Want, usbDeviceIds: Array): void
指定设备管理应用添加USB设备可用白名单。
需要权限: ohos.permission.ENTERPRISE_MANAGE_USB
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | [Want] | 是 | 设备管理应用。 |
usbDeviceIds | Array<[UsbDeviceId]> | 是 | USB设备ID数组。添加后的数组长度上限为1000。 |
错误码ID | 错误信息 |
---|---|
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. |
示例:
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let usbDeviceIds: Array<usbManager.UsbDeviceId> = [{
vendorId: 1,
productId: 1
}];
usbManager.addAllowedUsbDevices(wantTemp, usbDeviceIds);
console.info(`Succeeded in adding allowed USB devices.`);
} catch (err) {
console.error(`Failed to add allowed USB devices. Code: ${err.code}, message: ${err.message}`);
}