'java.lang.SecurityException: UID 10457 / PID 24525 lacks permission android.permission.BLUETOOTH
Android app giving:
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
I am trying to connect with Bluetooth thermal but am not able to do it in android 12
Solution 1:[1]
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. And then you can able to use the Bluetooth.
Example here I use library from here. 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();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ticherhaz FreePalestine |
