HarmonyOS 调用蓝牙接口access.enableBluetooth()报错 2900099, errMessage: BussinessError 2900099: Operation failed

HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

示例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%')
  }
}

是因为已经开启蓝牙了,才会报错。

分享
微博
QQ
微信
回复
3天前
相关问题
HarmonyOS 蓝牙ble写入失败 2900099
20浏览 • 1回复 待解决
HarmonyOS 调用屏幕截图接口报错801
26浏览 • 1回复 待解决
HarmonyOS 本地调用蓝牙问题
34浏览 • 1回复 待解决
webapp如何调用蓝牙
2149浏览 • 1回复 待解决
HarmonyOS 有无开关蓝牙的api接口
37浏览 • 1回复 待解决
HarmonyOS 蓝牙连接配对接口问题
41浏览 • 1回复 待解决