1

I'm building an app in CN1 that communicates with a BLE device (BlueGiga BLE module). In android 5.0 an CN1 app works as it should. In Android 6 the same app can't find any BLE devices. I can however connect manually to a specific BLE device (device address preset). So the scanning in Android 6 doesn't work. Based on this I figured out that I need to turn on GPS location and in the source add:

LocationManager locationManager = LocationManager.getLocationManager();

Is this a bug in CN1 or is it a problem in android? The default scanner in Android 6 (under Settings -> Bluetooth) and the app BlueGiga don't need to turn on GPS location (BlueGiga is written in Android). I also found the app BLE Scanner that does need to turn GPS location. Is it written in CN1?

Why is it necessary to turn on GPS location for BLE scanning to work on devices with Android 6?

Community
  • 1
  • 1
MetalHead
  • 181
  • 1
  • 15
  • 2
    BLE isn't a CN1 API, it's a CN1Lib to port the Cordova BLE library. Did you check that all of the needed permissions are granted before scanning? – James H May 04 '17 at 04:14
  • The permissions can be tricky, and make sure you're targeting at least API23, which Cordova requires. – James H May 04 '17 at 08:08
  • I tested on Android 5.0 (API21) and the scanning worked great. Then I also tested on Android 6.0 (API23) but the the scanning didn't work. It worked only after I added LocationManager in the source and turned on the location service. – MetalHead May 04 '17 at 09:21

1 Answers1

0

The location manager in Android doesn't necessarily map to GPS it maps to "hybrid location" which means it can take location from various sources and combine them into a single location.

I'm not familiar enough with that device but if it provides location it makes sense to "ask for location permissions" which is what we are doing here. As James mentioned in the comments this has nothing to do with the fact that the device is implemented as BLE as that's an external cn1lib and we just invoke the Android API's which abstract that.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • 1
    Thanks for the explanation. Seems like Android API23+ requies location to be turned on as explained: http://stackoverflow.com/a/41717429/7441780 and http://stackoverflow.com/a/41717433/7441780. – MetalHead May 04 '17 at 09:54
  • 2
    It's turned on implicitly when you use the LocationManager – Shai Almog May 05 '17 at 04:05