如果你的项目的targetsdkversion为31,即Android 12或者以上,根据Android 12新添加的蓝牙特性,
你需要配置下面这些权限才可以正常使用。
崩溃很可能是权限错误导致:
<!-- Needed only if your app looks for Bluetooth devices.
You must add an attribute to this permission, or declare the
ACCESS_FINE_LOCATION permission, depending on the results when you
check location usage in your app. -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- Needed only if your app makes the device discoverable to Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
详细描述文章:https://developer.android.com/about/versions/12/features/bluetooth-permissions?hl=zh-cn
评论
0 条评论
请登录写评论。