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

Android 13下Kivy应用蓝牙权限报错求助:需BLUETOOTH_CONNECT权限

解决方案

1. 更新buildozer.spec的权限配置

Android 13(API 33)对蓝牙权限进行了细分,原有的BLUETOOTH和BLUETOOTH_ADMIN权限已不足以完成绑定设备访问操作。你需要在buildozer.spec中添加BLUETOOTH_CONNECT权限:

android.permissions = BLUETOOTH, BLUETOOTH_ADMIN, BLUETOOTH_CONNECT

保留旧权限是为了兼容Android 11及以下版本。

2. 动态申请危险权限

Android 6.0(API 23)及以上版本要求危险权限必须在运行时动态申请,BLUETOOTH_CONNECT属于危险权限范畴,仅在manifest中声明无法生效。推荐使用plyer库简化权限请求操作:

步骤1:添加plyer依赖到buildozer.spec

requirements = python3,kivy,plyer

步骤2:在Kivy应用中添加权限请求代码

from kivy.app import App
from plyer import permissions
from plyer.utils import platform

class BluetoothDataApp(App):
    def on_start(self):
        if platform == 'android':
            # 动态请求BLUETOOTH_CONNECT权限
            permissions.request_permissions([permissions.BLUETOOTH_CONNECT])

if __name__ == '__main__':
    BluetoothDataApp().run()

问题原因说明

Android 13将原有的单一BLUETOOTH权限拆分为三个细分权限:

  • BLUETOOTH_SCAN:用于扫描蓝牙设备
  • BLUETOOTH_CONNECT:用于连接蓝牙设备、访问已绑定设备列表
  • BLUETOOTH_ADVERTISE:用于蓝牙广播

你的应用调用getBondedDevices()获取已绑定设备列表,必须持有BLUETOOTH_CONNECT权限,且需要在运行时主动向用户申请该权限,否则会触发SecurityException。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 01:25:14