Application I'm working on uses both Locations and BLE and if location or bluetooth are disabled I have to ask user to enable them.
Latest Google Play Services provides a standard way to do that using LocationSettingsRequest
which checks requirements and raises standard popup if changes to settings are required. It works like a charm for location alone but once I add SetNeedBle (true)
to LocationSettingsRequest
I get a status SETTINGS_CHANGE_UNAVAILABLE
.
The only my guess was I need to add AddApi (FitnessClass.BLE_API)
call to a GoogleApiClientBuilder
as it might be vital for BLE functionality, but then I got connection to Google Play Services failed with SIGN_IN_REQUIRED
status which is confusing as I just need BLE part of Fitness service.
Does anyone know good example of LocationSettingsRequest
usage to prompt user for both locations and bluetooth?
You are very close. In the
LocationSettingsRequest.Builder
there issetNeedBle(boolean needBle)
which will pop up a dialog box to ask for BLE. Don't use the Fitness API for BLE location.Also ensure that the phone is BLE enable by adding into the manifest:
Then in you code :
And from Google Play Service you can use the SettingApi which ask the system about available features. The guide contains a full example of how to use it.
https://developers.google.com/android/reference/com/google/android/gms/location/LocationSettingsRequest.Builder.html#setNeedBle(boolean)
Look like it has been fixed in 8.1.0 so
SetNeedBle (true)
works as expected: