Ionic 蓝牙(BLE)设备未出现在离子电容器应用程序中

tpgth1q7  于 5个月前  发布在  Ionic
关注(0)|答案(1)|浏览(76)

我有一个带有@capacitor-community/bluetooth-le插件的离子电容器应用程序。操作系统检测到信标,但我的应用程序没有。该问题仅发生在Android 13的设备上。
这是我的离子信息输出

Ionic:

   Ionic CLI                     : 7.1.5 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 7.5.5
   @angular-devkit/build-angular : 17.0.1
   @angular-devkit/schematics    : 17.0.1
   @angular/cli                  : 17.0.1
   @ionic/angular-toolkit        : 9.0.0

Capacitor:

   Capacitor CLI      : 5.5.1
   @capacitor/android : 5.5.1
   @capacitor/core    : 5.5.1
   @capacitor/ios     : not installed

Utility:

   cordova-res (update available: 0.15.4) : 0.15.3
   native-run (update available: 2.0.0)   : 1.7.4

System:

   NodeJS : v20.9.0 (/usr/local/bin/node)
   npm    : 10.1.0

字符串
这是我的Java版本Java版本“1.8.0_361”Java(TM)SE虚拟机环境(build 1.8.0_361-b 09)Java HotSpot(TM)64位服务器虚拟机(build 25.361-b 09,混合模式)
这是我的app.component.ts文件

import { Component, OnInit } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import { BleClient } from '@capacitor-community/bluetooth-le';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent implements OnInit {
  isLocationEnabled: any;
  isBLEEnabled: any;
  deviceId: any;
  ble: boolean = false;
  devices: any[] = [];
  response: any;

  constructor(
  ) {}

  async ngOnInit() {
  try {
    if (Capacitor.getPlatform() == 'android'){
      this.isLocationEnabled = await BleClient.isLocationEnabled();
    } else {
      this.isLocationEnabled = true;
    }
    await BleClient.initialize();
    this.isBLEEnabled = await BleClient.isEnabled();
    if (this.isBLEEnabled && this.isLocationEnabled) {
      this.ble = true;
      this.startScanning();
    }
    } catch (error) {
      console.error(error)
    }
  }

  startScanning() {
      BleClient.requestLEScan({ allowDuplicates: false }, (res1) => {
        console.log('Device found', res1)  
      });
  }
}

brvekthn

brvekthn1#

我刚刚看了一下bluetooth-le capacitor plugin的GitHub页面,发现了一些有趣的东西,可以解释你的问题:
安装指南包含有关Android 12及更高版本的蓝牙扩展的一节,其中提到了androidNeverForLocation标志,并给出了以下提示:
注意:如果您在android:usesPermissionFlags中包含neverForLocation,则会从扫描结果中筛选出一些BLE信标。
这在Android指南中也有解释。
我猜是你设置了旗子,所以信标找不到。

相关问题