[英]java.lang.SecurityException: UID 10457 / PID 24525 lacks permission android.permission.BLUETOOTH
Android app giving: Android应用程序给予:
java.lang.SecurityException: UID 10457 / PID 24525 lacks permission android.permission.BLUETOOTH
When I try to connect with Bluetooth printer using BluetoothDevice().connect() in Xiaomi android 12当我尝试在小米 android 12 中使用 BluetoothDevice().connect() 连接蓝牙打印机时
I am trying to connect with Bluetooth thermal but am not able to do it in android 12我正在尝试连接蓝牙热,但无法在 android 12 中进行
First you have to add user-permission.首先,您必须添加用户权限。
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
And then your codes, you have to check if the user is using Android 12. If yes, check the permission Bluetooth.然后您的代码,您必须检查用户是否使用 Android 12。如果是,请检查蓝牙权限。 And then you can able to use the Bluetooth.
然后你就可以使用蓝牙了。
Example here I use library from here.此处的示例我使用此处的库。 https://github.com/Karumi/Dexter
https://github.com/Karumi/Dexter
private void checkPermissionBluetooth() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
final ArrayList<String> listPermission = new ArrayList<>();
listPermission.add(Manifest.permission.BLUETOOTH_CONNECT);
listPermission.add(Manifest.permission.BLUETOOTH_SCAN);
Dexter.withContext(Kpp02NewActivity.this).withPermissions(listPermission).withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {
threadBluetoothEnable();
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
}
}).check();
} else {
threadBluetoothEnable();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.