【发布时间】:2017-02-01 16:30:14
【问题描述】:
与 BLE 设备配对后,函数 android.bluetooth.BluetoothDevice.setPairingConfirmation 被调用,这会导致应用崩溃:
Fatal Exception: java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission: Neither user 10168 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
at android.os.Parcel.readException(Parcel.java:1684)
at android.os.Parcel.readException(Parcel.java:1637)
at android.bluetooth.IBluetooth$Stub$Proxy.setPairingConfirmation(IBluetooth.java:1566)
at android.bluetooth.BluetoothDevice.setPairingConfirmation(BluetoothDevice.java:1182)
at nl.myapp.ui.main.NotificationFragment.onDeviceSelected(SourceFile:374)
at nl.myapp.ui.main.FindGlassDialogFragment.onDeviceClicked(SourceFile:224)
at nl.myapp.ui.main.adapters.DeviceAdapter$2.onClick(SourceFile:61)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
该应用在开发时运行良好。
当我关闭device.setPairingConfirmation() 线时,应用程序正在运行,但蓝牙设备不会停止其配对模式。
我有
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
在我的清单中,我要求在 Android 版本 M 及更高版本中获得运行时权限 ACCESS_COARSE_LOCATION。
我尝试请求 BLUETOOTH_ADMIN 和 BLUETOOTH_PRIVILEGED 作为运行时权限,但它们没有提示对话框。
这是当前 Android 版本中的错误吗?我确定该应用在 12 月 13 日发布时没有崩溃。
它发生在 Android 6 和 7 上。 我在装有 Android 7.1.1 的 Nexus 6P 上对其进行了测试。
【问题讨论】:
-
您的应用程序不能持有
BLUETOOTH_PRIVILEGED,因为这是signature|privileged权限,除非您的应用程序由固件签名密钥签名或安装为系统(“特权”)应用程序。setPairingConfirmation()被记录为需要BLUETOOTH_PRIVILEGED,所以大概这是按预期工作的。我无法解释它以前是如何工作的,我也不知道解决方法是什么,如果有的话。 -
好的,所以我现在在文档中阅读的第 3 方应用程序无法使用 BLUETOOTH_PRIVILEGED 权限。但是当我查看 setPairingConfirmation() 的来源时,它需要 BLUETOOTH_ADMIN。也许谷歌在安全更新中改变了这一点......
标签: android bluetooth permissions bluetooth-lowenergy