EddyVerbruggen / nativescript-bluetooth-demo

30 stars 21 forks source link

Android 6: Scan does not find any devices #4

Closed lhitc closed 8 years ago

lhitc commented 8 years ago

This is when I hit the "Any Device" button in the demo app.

I have not investigated in deep atm, but there are several caveats concerning this.

First: in Android 5+ an application needs location permission for BT LE scan to work. So in the module's platforms/android/AndroidManifest.xml, there should be the following:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

or

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

See: http://stackoverflow.com/questions/32708374/bluetooth-le-scanfilters-dont-work-on-android-m

Also there is a comment in that posting about the dynamic permission request for Android 6: "Starting with Android 6, you must also present a permission request to a usr at runtime.", pointing to the following example: http://developer.radiusnetworks.com/2015/09/29/is-your-beacon-app-ready-for-android-6.html

Apart from that I'm not quite sure whether it is a good idea to forcefully use Android's 3-parameter-startScan method BluetoothLeScanner.startScan(filters, settings, callback)

There are known issues especially with the filters, which leads to the hint you find in several threads on StackOverflow: if you want to be safe, don't use scanFilters (meaning: you got to loop through the scan results later on to find the desired device). I'd very much prefer to have at least the possibility to use Android's 1-parameter version BluetoothLeScanner.startScan(callback) either by flag or automagically when there are no filter UUIDs defined.

Edit: Just to exclude hardware or user problems: other tools like "BLE Scanner" from the Play Store or my own prototypish NativeScript Android only Bluetooth Scanner app do find the peripherals.

EddyVerbruggen commented 8 years ago

Really happy with your Android 6 tests! So I'll add those permission methods (I've done it before for other plugins).

And I'm going to make sure I'll pass in null when no filters need to be applied that should effectively yield the same result, but I'm glad you're able to compare it with other apps - I like that approach.

EddyVerbruggen commented 8 years ago

Please retest when you have time.