如题:HarmonyOS 调用蓝牙接口access.enableBluetooth()报错 2900099, errMessage: BussinessError 2900099: Operation failed?
示例demo如下:import { BusinessError } from '@ohos.base'; import { access } from '@kit.ConnectivityKit'; import { abilityAccessCtrl, common } from '@kit.AbilityKit'; @Entry @Component struct TestBluetooth { @State message: string = 'Hello World'; private atManager = abilityAccessCtrl.createAtManager(); private appContext: common.Context = getContext(this); async requestPermissionsFn() { console.info(`requestPermissionsFn entry`); try { this.atManager.requestPermissionsFromUser(this.appContext, [ 'ohos.permission.ACCESS_BLUETOOTH' ]).then(() => { console.info(`request Permissions success!`); }) } catch (err) { console.info(`requestPermissionsFromUser call Failed! error: ${err.code}`); } } aboutToAppear(): void { this.requestPermissionsFn(); } build() { RelativeContainer() { Text(this.message) .id('TestBluetoothHelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }) .onClick(()=>{ try { access.enableBluetooth(); console.info('wangyi success') } catch (err) { console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); } }) } .height('100%') .width('100%') } }是因为已经开启蓝牙了,才会报错。
示例demo如下:
是因为已经开启蓝牙了,才会报错。