How to pop up Enable Bluetooth prompt from Google Play Services?

左心房为你撑大大i 提交于 2019-12-05 17:27:55

You are very close. In the LocationSettingsRequest.Builder there is setNeedBle(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:

<manifest>
<uses-feature
        android:name="android.hardware.bluetooth_le"
        android:required="false" />
</manifest>

Then in you code :

if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
    //has BLE
}

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!