【问题标题】:Apps starts crashing since end december 2016 at setPairingConfirmation because of missing BLUETOOTH_ADMIN permission由于缺少 BLUETOOTH_ADMIN 权限,应用程序自 2016 年 12 月下旬在 setPairingConfirmation 开始崩溃
【发布时间】: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


【解决方案1】:

即使您在清单中写入权限,也可能会关闭蓝牙权限。用户有权拒绝某些权限。您必须要求用户在运行时授予权限。这个链接会帮助你Android requesting permission from the user

您可以通过设置 -> 已安装的应用程序 -> 找到您的应用程序然后查找其权限来确认权限是否关闭

【讨论】:

  • 蓝牙权限不是运行时权限。当我在运行时请求它们时,不会提示它们。
  • 您是否在设置中检查了权限是关闭还是打开
  • 显然 Google 在安全更新中更改了某些内容,因此 setPairingConfirmation() 不再可用于外部应用程序。它只能由批准的应用程序和 Android 系统使用。它现在需要 BLUETOOTH_PRIVILEGED 而不是 BLUETOOTH_ADMIN(在 2016 年 12 月结束之前)。我想我不需要这个功能,我可能误解了它的使用。
  • 罗尔,我认为你是对的。白痴。由于没有弹出用户菜单询问“您要与此设备配对吗?”的 Android 错误,情况变得更糟。当设备发送安全请求时。
猜你喜欢
  • 2018-06-12
  • 2018-09-14
  • 1970-01-01
  • 2015-04-17
  • 1970-01-01
  • 2016-08-20
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多