android-permissionsandroid-bluetoothsamsung-mobileandroid-12

java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission


After asking for runtime permission for BLUETOOTH_CONNECT, android 12 crashes , I faced this problem in Samsung Android 12 Device. In other device less then Android 12 is working fine.

I handled bluetooth permission but still my app going to crash

manifest

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

sdk -> 31

Showing this type of error after build the app.


Solution

  • I got the solution.

    As you can see the BLUETOOTH permission is disabled in Android 12. This issue resolved if I add the maxSdkVersion for the BLUETOOTH permission. So I update permissions in manifest file :

    Old This:

    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    

    to

    new this:

    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" android:required="false" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:maxSdkVersion="30"  android:required="false" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"  android:required="false" />