don / cordova-plugin-ble-central

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)
Apache License 2.0
941 stars 601 forks source link

Scan result - No error but totally blank #976

Closed clarklight closed 11 months ago

clarklight commented 11 months ago

I used the @slim version and have the permissions below, when i copied and pasted in the demo code to test out a scan, it says scan completed, but returned no item, but i have atleast a few bluetooth device next to me??? Any pointer?

Thanks Clark

    <config-file target="AndroidManifest.xml" parent="/manifest">
        <uses-permission android:name="android.permission.CAMERA" android:maxSdkVersion="30" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
        <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
        <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
        <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
        <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
        <uses-permission android:name="android.permission.RECORD_AUDIO" />

    </config-file>
peitschie commented 11 months ago

@clarklight sounds interesting!

Which version of Android are you running this with? Is Location enabled on this phone? Are you able to provide the snippet you're using to do the scan?

It's also worth doing a scan with nrf Connect as well just to make sure the Bluetooth devices you're looking at are all actively advertising.

clarklight commented 11 months ago

@peitschie Thank you so much for the quick pointer!! I managed to get it to work, i did have Location setting, but i didnt know that it won't give me a prompt if it isnt turned on, i just turned the Location on, and it is showing the devices now!! Thank you so much! Clark

peitschie commented 11 months ago

Fantastic. Glad it was resolved so readily.

Just as a bit of background location services are not required on all phones or Android versions to scan... so it's a bit hit and miss as to whether it's needed or not. Hence, the plugin itself doesn't reject a scan even when location services are disabled because we have no way of knowing if the scan works or not.

There are APIs available to listen for updates to the location services if you need them in your app: https://github.com/don/cordova-plugin-ble-central#islocationenabled