[英]Finding Error in android studio java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT
I am new to Android studio.我是 Android 工作室的新手。 I am trying to connect to brother label printer QL-820NMB with the new Android APK (SDK 31) with android version 12 and the device is also android 12 itself.
我正在尝试使用新的 Android APK(SDK 31)和 android 版本 12 连接到兄弟 label 打印机 QL-820NMB,并且该设备本身也是 android 12。 I tried pairing the device it gets paired.
我尝试配对它配对的设备。 But when I tried to access the paired devices in the code finding the error in the line
但是当我尝试访问代码中的配对设备时发现行中的错误
Set<BluetoothDevice> pairedDevices = BluetoothAdapter.getBondedDevices();
And Exception is...例外是...
System.err: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 0000, packageName = com.xyz.xyz, attributionTag = null, token = android.os.xyz, next = null }: AdapterService getBondedDevices
I have provided all the manifest for permissions.我已经提供了所有权限清单。
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
and also updated the mobile updates recommended and also updated the BrotherPrintLibrary jar to aar as recommended file.还更新了推荐的移动更新,并将 BrotherPrintLibrary jar 更新为 aar 作为推荐文件。
But still unable to access the Bluetooth and getting the same Security Exception as above is there any solution or can I know am I missing any configuration issue in the mobile or the code.但仍然无法访问蓝牙并获得与上述相同的安全异常是否有任何解决方案,或者我可以知道我是否遗漏了移动设备或代码中的任何配置问题。
I forgot to mention the same APK is working fine in Android 7 device but not in Android 12.我忘了说同一个 APK 在 Android 7 设备上运行良好,但在 Android 12 设备上运行良好。
Seems, you missed BLUETOOTH_ADMIN Permission.看来,您错过了 BLUETOOTH_ADMIN 权限。
https://developer.android.com/guide/topics/connectivity/bluetooth/permissions https://developer.android.com/guide/topics/connectivity/bluetooth/permissions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.