Android:即使在LocationSettingsRequest中使用setEnableBle之后,也无法扫描BLE设备

时间:2019-12-10 07:49:55

标签: android google-play-services android-location android-ble

在我的应用中,我想同时使用GPS和BLE搜索附近的用户。我碰到了SettingsClient,它通过显示弹出框(如果未启用)来启用GPS。

有趣的是,它还有一个setNeedBle方法,根据文档

  

设置客户端是否希望启用BLE扫描。当这个标志   如果平台支持BLE扫描模式和蓝牙,则设置为true   如果关闭,对话框将提示用户启用BLE扫描。如果   平台不支持BLE扫描模式,对话框将提示您   启用蓝牙。

这对我来说是完美的。如果当蓝牙关闭时我可以扫描BLE设备,那就太好了。我跟随this official guide进行了设置,然后看到了这样的弹出窗口。

enter image description here

但是当我尝试对附近的设备进行BLE扫描时选择“确定”后,会出现此错误。

    java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission: Neither user 10834 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
        at android.os.Parcel.createException(Parcel.java:1950)
        at android.os.Parcel.readException(Parcel.java:1918)
        at android.os.Parcel.readException(Parcel.java:1868)
        at android.bluetooth.IBluetoothGatt$Stub$Proxy.startScan(IBluetoothGatt.java:947)
        at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper.onScannerRegistered(BluetoothLeScanner.java:460)
        at android.bluetooth.le.IScannerCallback$Stub.onTransact(IScannerCallback.java:57)
        at android.os.Binder.execTransact(Binder.java:731)

显然,这表明我需要第三方应用程序不具备的权限BLUETOOTH_PRIVILEGED

我很困惑,如果只有系统应用程序可以使用setNeedBle函数,那还有什么意义呢?还是我错过了什么?是否可以使用此权限进行BLE扫描,或者我必须要求用户启用蓝牙?谢谢!

0 个答案:

没有答案