简体   繁体   中英

Issue with the cordova plugin ble-central

I'm new in the world of the Ionic framework and I'm developing an Ionic app using bluetooth-low-energy (the cordova plugin ble-central). Everything has worked well until two days ago. Now, the scan() function doesn't work anymore. The function is correctly called and the bluetooth and location permission are allowed. I've made no changes on my code that would explain this issue. I've also tried to uninstall/install the app, reboot my android phone and also used another phone. Nothing work.

Below a snips of my manifest:

<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" />

and the bluetooth code:

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');

The function setStatus is for debugging.

I've read and tried a lot of things but nothing work. Thanks for your help!

PS: Of course, the bluetooth and the gps are active when I'm using my app.

Since android api 29, ACCESS_FINE_LOCATION permission is used instead of ACCESS_COARSE_LOCATION. The mantainer of cordova-plugin-ble-central have not accepted a pull request that correct this issue yet.

I did the necessary changes on my fork and it is working fine now on android 10, api 29...

Maybe you can use it by removing the old:

ionic cordova plugin rm cordova-plugin-ble-central

And adding my fork:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM