javascript - cordova 插件 ble-central 的问题

标签 javascript android ionic-framework bluetooth bluetooth-lowenergy

我是 Ionic 框架领域的新手,我正在使用蓝牙低能量(cordova 插件 ble-central)开发一个 Ionic 应用程序。直到两天前一切都运转良好。现在,scan() 函数不再起作用。函数调用正确,且允许蓝牙和位置权限。我没有对我的代码进行任何可以解释此问题的更改。我还尝试卸载/安装该应用程序,重新启动我的 Android 手机,并使用另一部手机。没有任何效果。

下面是我的 list 的 fragment :

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-feature android:name="android.hardware.location.gps" />

和蓝牙代码:

this.ble.scan([], 5).subscribe( 
              device => 
                  this.onDeviceDiscovered(device),// Never reached
              error => { 
                  this.scanError(error).catch(e => console.log('scan error ' + e)); // Never reached
              },
              () => console.log('completed')); // Never reached


          // Debug
          setTimeout(this.setStatus.bind(this), 6000, 'Scan completed');

函数setStatus用于调试。

我已经阅读并尝试了很多东西,但没有任何效果。 感谢您的帮助!

PS:当然,当我使用我的应用程序时,蓝牙和 GPS 处于 Activity 状态。

最佳答案

自 android api 29 起,使用 ACCESS_FINE_LOCATION 权限而不是 ACCESS_COARSE_LOCATION。 cordova-plugin-ble-central 的维护者尚未接受纠正此问题的拉取请求。

我对我的 fork 进行了必要的更改,现在它在 android 10、api 29 上运行良好...

也许您可以通过删除旧的来使用它:

ionic cordova plugin rm cordova-plugin-ble-central

并添加我的 fork :

ionic cordova plugin add git+https://github.com/dslima90/cordova-plugin-ble-central.git

关于javascript - cordova 插件 ble-central 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63501872/

相关文章:

javascript - Firebase "once"事件不返回 promise

javascript - Ionic 两侧菜单模式在添加更多内容时不会自动滚动

ionic-framework - 如何强制手机仅显示屏幕方向 "portrait",平板电脑仅显示屏幕方向 "landscape"?

javascript - Ionic 3 - ionic 选择(多个)在选择两个项目后禁用所有选项

javascript - 突出显示 Angular * ngFor中的选定元素

javascript - 是否可以在不重新加载页面的情况下使用 JavaScript 更改文档类型?

javascript - 如何使用 next-auth 获取额外的范围数据?

java - Veracode CWE ID 404 资源关闭或释放不当

java - 如何从 NDK(JNI) 调用特定的 Java 方法?

java - android.permission.BATTERY_STATS 用法