【发布时间】:2015-06-01 17:27:46
【问题描述】:
我的应用运行良好,直到 Android 5.0.2 不允许第三方应用通过低功耗蓝牙连接到 HID 设备。
myGatt.setCharacteristicNotification(gattChar, true);
06-01 17:39:35.356: W/BluetoothGatt(21599):
java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission:Neither
user 10157 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
BLUETOOTH_PRIVILEGED 权限不适用于第三方应用。它仅适用于系统或制造商应用程序。
Android 注意的最新变化: 对 HID-over-GATT 实施 BLUETOOTH_PRIVILEGED 权限 https://android.googlesource.com/platform/packages/apps/Bluetooth/+/02bebee
Code snippet:
private static final UUID[] HID_UUIDS = {
UUID.fromString("00002A4A-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4B-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4C-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4D-0000-1000-8000-00805F9B34FB") };
if (isHidUuid(charUuid)) enforcePrivilegedPermission();
我的问题:有没有办法覆盖 HID_UUIDS 或强制执行PrivilegedPermission?我可以使用反射来绕过它吗?
Android 每次发布新版本,都会破坏之前的代码。
谢谢!
【问题讨论】:
标签: android bluetooth-lowenergy gatt