问题描述
全部异常信息大致如下,发生在进行蓝牙扫描阶段:
W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission: Neither user 10179 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:450)
at android.bluetooth.le.IScannerCallback$Stub.onTransact(IScannerCallback.java:57)
at android.os.Binder.execTransact(Binder.java:731)
解决方案
不用去找 android.permission.BLUETOOTH_PRIVILEGED 权限的事情了,声明也无效,解决方法就是如果蓝牙处于关闭状态手动开启蓝牙即可。
Google官方对于此权限的解释为:
允许应用程序在没有用户交互的情况下配对蓝牙设备,并允许或禁止电话簿访问或消息访问
但实际上我们的操作是有用户交互产生的,此问题纯属 Google 犯傻导致,经查证开启蓝牙开关后问题消失。
参考:
https://developer.android.com/reference/android/Manifest.permission
网友评论