SetNeedBle from SettingsApi does not work with API23

I use com.google.android.gms.location.SettingsApi to turn on Bluetooth and location in my Android app. A dialog box appears prompting the user to turn it on when it is turned off so that my application can scan neighboring Bluetooth devices. I followed the instructions in the reference guide ( https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi ). This is pretty simple: first you connect to GoogleApiClient and then create LcoationSettingsRequest.builder:

LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() .addLocationRequest(mLocationRequestHighAccuracy) .setNeedBle(true) 

In my case, I added setNeedBle (true), since I also need to enable Bluetooth. Then you call checkLocationSettings from SettingsApi and add the callback to the result. A dialog box appears prompting the user to turn on Bluetooth and location, and you will receive a callback, regardless of whether the user has chosen to do this or not.

This works fine on a device with API22 and Google Play Services 8.4.89, but not on the same device with API23 and GPS version 8.4.89. This is only the part of setNeedBle (true) that does not work on API23: when Bluetooth is turned off, I do not get a dialog (but the dialog to enable the location works fine). Since both of them have the same GPS version, it is related to API22 and API23. Does anyone know if this is a mistake or how can I solve this problem?

I found a similar question ( "How to pop up" Turn on the Bluetooth prompt from Google Play Services "?) About this, but it is suggested that it is fixed in GPS 8.1 but I use GPS v8.4. Also, this is a slightly different problem, since I do not get the status of SETTINGS_CHANGE_UNAVAILABLE.

+5
source share
2 answers

If a client uses BLE scans to retrieve a location, he can request BLE activation by calling setNeedBle (boolean) .

Please refer to the solution: https://github.com/googlemaps/android-samples/tree/master/ApiDemos (if you want to grant permission to API 23 (Android M) during runtime.)

Also refer to the official repo:
https://developer.android.com/training/location/change-location-settings.html
https://developer.android.com/about/versions/marshmallow/android-6.0.html#bluetooth-stylus

Hope this helps.

0
source

The location service in API 23 has a Scan settings panel.

location

Switches are used to improve location accuracy for Wi-Fi and Bluetooth.

scan

By enabling it, the location service can use BLE scanning even if Bluetooth is not turned on . In this case, setNeedBle(true) will not prompt the user to open Bluetooth, as the location service can already use BLE.

But I don’t know how to make BLE scanning in the location service available in our own application, maybe this is not possible.

I suggest checking if Bluetooth is turned on after the request location service and showing a prompt to turn on Bluetooth if it’s not turned on.

0
source

Source: https://habr.com/ru/post/1244149/


All Articles