郑州做公司网站的,wordpress 最新主题,商务局网站群建设方案,网站建设流程图设备管理
本模块提供分布式设备管理能力。
系统应用可调用接口实现如下功能#xff1a;
注册和解除注册设备上下线变化监听发现周边不可信设备认证和取消认证设备查询可信设备列表查询本地设备信息#xff0c;包括设备名称#xff0c;设备类型和设备标识 说明#xff1a…设备管理
本模块提供分布式设备管理能力。
系统应用可调用接口实现如下功能
注册和解除注册设备上下线变化监听发现周边不可信设备认证和取消认证设备查询可信设备列表查询本地设备信息包括设备名称设备类型和设备标识 说明 本模块首批接口从API version 7开始支持。后续版本的新增接口采用上角标单独标记接口的起始版本。本模块接口为系统接口三方应用不支持调用。 导入模块
import deviceManager from ohos.distributedHardware.deviceManager;deviceManager.createDeviceManager
createDeviceManager(bundleName: string, callback: AsyncCallback): void
创建一个设备管理器实例。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 参数名类型必填说明bundleNamestring是指示应用程序的包名。callbackAsyncCallback[DeviceManager]是DeviceManager实例创建时调用的回调返回设备管理器对象实例。 示例 deviceManager.createDeviceManager(ohos.samples.jshelloworld, (err, data) { if (err) { console.info(createDeviceManager err: JSON.stringify(err)); return;}console.info(createDeviceManager success);this.dmInstance data;
});DeviceInfo
设备信息。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称类型必填描述deviceIdstring是设备的唯一标识。deviceNamestring是设备名称。deviceType[DeviceType]是设备类型。networkId8string是设备网络标识。
DeviceType
表示设备类型的枚举类。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称默认值说明SPEAKER0x0A智能音箱PHONE0x0E手机TABLET0x11平板WEARABLE0x6D智能穿戴TV0x9C智慧屏CAR0x83车UNKNOWN_TYPE0未知设备
DeviceStateChangeAction
表示设备状态变化的枚举。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称默认值说明ONLINE0设备上线。READY1设备就绪设备信息同步已完成。OFFLINE2设备下线。CHANGE3设备信息更改。
SubscribeInfo
发现信息。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称类型必填描述subscribeIdnumber是发现标识用于标识不同的发现周期。mode[DiscoverMode]否发现模式。medium[ExchangeMedium]否发现类型。freq[ExchangeFreq]否发现频率。isSameAccountboolean否是否同账号。isWakeRemoteboolean否是否唤醒设备。capability[SubscribeCap]否发现能力。
DiscoverMode
表示发现模式的枚举。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称默认值说明DISCOVER_MODE_PASSIVE0x55被动模式。DISCOVER_MODE_ACTIVE0xAA主动模式。
ExchangeMedium
表示发现类型的枚举。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称默认值说明AUTO0自动发现类型。BLE1蓝牙发现类型。COAP2WiFi发现类型。USB3USB发现类型。
ExchangeFreq
表示发现频率的枚举。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称默认值说明LOW0低频率。MID1中频率。HIGH2高频率。SUPER_HIGH3超高频率。
SubscribeCap
表示发现能力的枚举。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称默认值说明SUBSCRIBE_CAPABILITY_DDMP0DDMP能力后续会被废弃。SUBSCRIBE_CAPABILITY_OSD1OSD能力。
AuthParam
认证参数。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称类型必填描述authTypenumber是认证类型。extraInfo{[key:string] : any}否认证参数可扩展字段。
AuthInfo
认证信息。
系统能力以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager
名称类型必填描述authTypenumber是认证类型。tokennumber是认证Token。extraInfo{[key:string] : any}否认证信息可扩展字段。
DeviceManager
设备管理实例用于获取可信设备和本地设备的相关信息。在调用DeviceManager的方法前需要先通过createDeviceManager构建一个DeviceManager实例dmInstance。
release
release(): void
设备管理实例不再使用后通过该方法释放DeviceManager实例。
系统能力SystemCapability.DistributedHardware.DeviceManager 示例 dmInstance.release();getTrustedDeviceListSync
getTrustedDeviceListSync(): Array
同步获取所有可信设备列表。
系统能力SystemCapability.DistributedHardware.DeviceManager 返回值 名称说明Array[DeviceInfo]返回可信设备列表。 示例 var deviceInfoList dmInstance.getTrustedDeviceListSync();getTrustedDeviceList8
getTrustedDeviceList(callback:AsyncCallbackArray): void
获取所有可信设备列表。使用callback异步回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明callbackAsyncCallbackArray[DeviceInfo]是获取所有可信设备列表的回调返回设备信息。 示例 dmInstance.getTrustedDeviceList((err, data) {console.log(getTrustedDeviceList err: JSON.stringify(err));console.log(get trusted device info: JSON.stringify(data));}
);getTrustedDeviceList8
getTrustedDeviceList(): PromiseArray
获取所有可信设备列表。使用Promise异步回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 返回值 类型说明PromiseArray[DeviceInfo]Promise实例用于获取异步返回结果。 示例 dmInstance.getTrustedDeviceList().then((data) { console.log(get trusted device info: JSON.stringify(data));
}).catch((err) {console.log(getTrustedDeviceList err: JSON.stringify(err));
});getLocalDeviceInfoSync8
getLocalDeviceInfoSync(): [DeviceInfo]
同步获取本地设备信息。
系统能力SystemCapability.DistributedHardware.DeviceManager 返回值 名称说明Array[DeviceInfo]返回可信设备列表。 示例 var deviceInfo dmInstance.getLocalDeviceInfoSync();getLocalDeviceInfo8
getLocalDeviceInfo(callback:AsyncCallback): void
获取本地设备信息。使用callback异步回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明callbackAsyncCallback[DeviceInfo]是获取本地设备信息。 示例 dmInstance.getLocalDeviceInfo((err, data) {console.log(getLocalDeviceInfo err: JSON.stringify(err));console.log(get local device info: JSON.stringify(data));}
);getLocalDeviceInfo8
getLocalDeviceInfo(): Promise
获取本地设备信息。使用Promise异步回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 返回值 类型说明Promise[DeviceInfo]Promise实例用于获取异步返回结果。 示例 dmInstance.getLocalDeviceInfo().then((data) { console.log(get local device info: JSON.stringify(data));
}).catch((err) {console.log(getLocalDeviceInfo err: JSON.stringify(err));
});startDeviceDiscovery
startDeviceDiscovery(subscribeInfo: SubscribeInfo): void
发现周边设备。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明subscribeInfo[SubscribeInfo]是发现信息。 示例 //生成发现标识随机数确保每次调用发现接口的标识不一致
var subscribeId Math.floor(Math.random() * 10000 1000);
var subscribeInfo {subscribeId: subscribeId,mode: 0xAA, //主动模式medium: 0, //自动发现类型同时支持多种发现类型freq: 2, //高频率isSameAccount: false,isWakeRemote: false,capability: 1
};
dmInstance.startDeviceDiscovery(subscribeInfo); //当有设备发现时通过deviceFound回调通知给应用程序stopDeviceDiscovery
stopDeviceDiscovery(subscribeId: number): void
停止发现周边设备。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明subscribeIdnumber是发现标识。 示例 //入参需要和startDeviceDiscovery接口传入的subscribeId配对使用
dmInstance.stopDeviceDiscovery(subscribeId);authenticateDevice
authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback{deviceId: string, pinToken ?: number}): void
认证设备。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明deviceInfo[DeviceInfo]是设备信息。authParam[AuthParam]是认证参数。callbackAsyncCallback{ deviceId: string, pinToken ?: number }是认证结果回调。 示例 //认证的设备信息可以从发现的结果中获取
var deviceInfo {deviceId: XXXXXXXX,deviceName: ,deviceType: 0x0E
};
let authParam {authType: 1, //认证类型 1 - 无账号PIN码认证extraInfo: {}
}
dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) {if (err) {console.info(TAG authenticateDevice err: JSON.stringify(err));return;}console.info(TAG authenticateDevice result: JSON.stringify(data));token data.pinToken;
});unAuthenticateDevice8
unAuthenticateDevice(deviceInfo: DeviceInfo): void
解除认证设备。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明deviceInfo[DeviceInfo]是设备信息。 示例 dmInstance.unAuthenticateDevice(deviceInfo);verifyAuthInfo
verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback{deviceId: string, level: number}): void
验证认证信息。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明authInfo[AuthInfo]是认证信息。authInfoAsyncCallback{ deviceId: string, level: number }是验证结果回调。 示例 let authInfo {authType: 1,token: xxxxxx,extraInfo: {}
}
dmInstance.verifyAuthInfo(authInfo, (err, data) {if (err) {console.info(TAG verifyAuthInfo err: JSON.stringify(err));return;}console.info(TAG verifyAuthInfo result: JSON.stringify(data));
});on(‘deviceStateChange’)
on(type: ‘deviceStateChange’, callback: Callback{ action: DeviceStateChangeAction, device: DeviceInfo }): void
注册设备状态回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是注册设备状态回调固定为deviceStateChange。callbackCallback{ action: [DeviceStateChangeAction], device: [DeviceInfo] }是指示要注册的设备状态回调返回设备状态和设备信息。 示例 dmInstance.on(deviceStateChange, (data) { console.info(deviceStateChange on: JSON.stringify(data));}
);off(‘deviceStateChange’)
off(type: ‘deviceStateChange’, callback?: Callback{ action: DeviceStateChangeAction, device: DeviceInfo }): void
取消注册设备状态回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是根据应用程序的包名取消注册设备状态回调。callbackCallback{ action: [DeviceStateChangeAction], device: [DeviceInfo] }是指示要取消注册的设备状态回调返回设备状态和设备信息。 示例 dmInstance.off(deviceStateChange, (data) { console.info(deviceStateChange JSON.stringify(data));}
);on(‘deviceFound’)
on(type: ‘deviceFound’, callback: Callback{ subscribeId: number, device: DeviceInfo }): void
注册发现设备回调监听。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是注册设备发现回调以便在发现周边设备时通知应用程序。callbackCallback{ subscribeId: number, device: DeviceInfo }是注册设备发现的回调方法。 示例 dmInstance.on(deviceFound, (data) {console.info(deviceFound: JSON.stringify(data));}
);off(‘deviceFound’)
off(type: ‘deviceFound’, callback?: Callback{ subscribeId: number, device: DeviceInfo }): void
取消注册设备发现回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是取消注册设备发现回调。callbackCallback{ subscribeId: number, device: DeviceInfo }是指示要取消注册的设备发现回调返回设备状态和设备信息。 示例 dmInstance.off(deviceFound, (data) { console.info(deviceFound JSON.stringify(data));}
);on(‘discoverFail’)
on(type: ‘discoverFail’, callback: Callback{ subscribeId: number, reason: number }): void
注册设备发现失败回调监听。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是注册设备发现失败回调以便在发现周边设备失败时通知应用程序。callbackCallback{ subscribeId: number, reason: number }是注册设备发现失败的回调方法。 示例 dmInstance.on(discoverFail, (data) {this.log(discoverFail on: JSON.stringify(data));}
);off(‘discoverFail’)
off(type: ‘discoverFail’, callback?: Callback{ subscribeId: number, reason: number }): void
取消注册设备发现失败回调。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是取消注册设备发现失败回调。callbackCallback{ subscribeId: number, reason: number }是指示要取消注册的设备发现失败回调。 示例 dmInstance.off(deviceFound, (data) { console.info(deviceFound JSON.stringify(data));}
);on(‘serviceDie’)
on(type: ‘serviceDie’, callback: () void): void
注册设备管理服务死亡监听。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是注册serviceDie回调以便在devicemanager服务异常终止时通知应用程序。callback() void是注册serviceDie的回调方法。 示例 dmInstance.on(serviceDie, () { console.info(serviceDie on);}
);off(‘serviceDie’)
off(type: ‘serviceDie’, callback?: () void): void
取消注册设备管理服务死亡监听。
系统能力SystemCapability.DistributedHardware.DeviceManager 参数 名称参数类型必填说明typestring是取消注册serviceDie回调以便在devicemanager服务异常终止时通知应用程序。callback() void否取消注册serviceDie的回调方法。 示例 dmInstance.off(serviceDie, () { console.info(serviceDie off);}
);