You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 13应用崩溃:需BLUETOOTH PRIVILEGED权限排查

Android 13蓝牙崩溃:要求BLUETOOTH_PRIVILEGED权限问题排查

生产环境里的应用仅在Android 13设备上崩溃,已在Manifest中声明所有蓝牙相关权限,且获取了附近设备的运行时权限,但仍抛出SecurityException,提示需要BLUETOOTH_PRIVILEGED权限。

Manifest配置

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:installLocation="auto">

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission
        android:name="android.permission.BLUETOOTH_ADMIN"
        android:maxSdkVersion="33" />
    <uses-permission
        android:name="android.permission.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation"
        tools:ignore="UnusedAttribute" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  
    <uses-permission
        android:name="android.permission.ACCESS_COARSE_LOCATION"
        android:maxSdkVersion="31" />
    <uses-permission
        android:name="android.permission.ACCESS_FINE_LOCATION"
        android:maxSdkVersion="31" />
</manifest>

崩溃日志

Fatal Exception: java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission: Neither user 10370 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
       at android.app.ContextImpl.enforce(ContextImpl.java:2240)
       at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:2268)
       at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:948)
       at com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission(Utils.java:411)
       at com.android.bluetooth.gatt.GattService.permissionCheck(GattService.java:474)
       at com.android.bluetooth.gatt.GattService.registerForNotification(GattService.java:3801)
       at com.android.bluetooth.gatt.GattService$BluetoothGattBinder.registerForNotification(GattService.java:1085)
       at com.android.bluetooth.gatt.GattService$BluetoothGattBinder.registerForNotification(GattService.java:1073)
       at android.bluetooth.IBluetoothGatt$Stub.onTransact(IBluetoothGatt.java:812)
       at android.os.Binder.execTransactInternal(Binder.java:1285)
       at android.os.Binder.execTransact(Binder.java:1244)

解决办法

  1. 问题根源:Android 13中调用registerForNotification时,系统蓝牙服务会触发权限校验。BLUETOOTH_PRIVILEGED是系统级权限,普通应用无法获取。大概率是代码中要注册通知的蓝牙特征UUID属于系统预留的特殊服务(比如电池服务、健康监测服务等)。
  2. 具体修复:
    • 检查代码中调用registerForNotification的特征UUID,确认是否为系统服务UUID(例如0000180F-0000-1000-8000-00805F9B34FB是标准电池服务UUID)。
    • 如果是系统服务的特征,不要尝试注册通知——这类服务的通知由系统自身处理,普通应用无权监听。
    • 若业务需要相关数据,使用系统公开API替代,比如获取电池状态用BatteryManager,而非直接通过蓝牙监听。
    • 若为自定义设备的特征,检查设备端是否误用了系统预留UUID段,修改为自定义UUID即可。

内容的提问来源于stack exchange,提问作者Pratik Popat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 06:35:01