Need Help In Bluetooth Permission for an app on Android 12

which means, you will not be able to upload your project to Google Play
Taifun

1 Like

Hi Taifun,

Thanks for letting know about this. I'm aware you have built your own extension for Bluetooth client. I believe you have enough info and means to solve the issue. Can you please help us.

that is true Anke.
I just tried the same but with targetSdkVersion="31" instead, and the bug is there again with the pop up : "need android.permission.BLUETOOTH_CONNECT .... "

But if we set to 31, then app throws an error for Bluetooth permission. How do we solve the issue then?

Also you can no longer upload / release an APK to the Play Store as long as the app (as APK) has not already been released before August 1st, 2021.

Will not help too much but targetSdkVersion="30" works also

In my bluetooth client extension I introduced a method to ask for permissions like this
in my tests this was working up to now...
Unbenannt2

Taifun

  /**
   * RequestBluetoothPermission
   */
  @SimpleFunction(description = "Request Bluetooth Permission.")
  public void RequestBluetoothPermission() {
    Log.d(LOG_TAG, "RequestBluetoothPermission");


    if (isRepl)
    {
      ErrorOccurred("You will have to build the app to be able to test this method.");
    } else if (ApiLevel()>30){
      ActivityCompat.requestPermissions(form,
          new String[] {
              "android.permission.BLUETOOTH_CONNECT",
              "android.permission.BLUETOOTH_SCAN",
              "android.permission.BLUETOOTH_ADVERTISE",
              "android.permission.ACCESS_FINE_LOCATION"
          }, BLUETOOTH_PERMISSION_REQUEST_CODE
      );
    } else {
      ActivityCompat.requestPermissions(form,
          new String[] {
              "android.permission.ACCESS_FINE_LOCATION"
          }, BLUETOOTH_PERMISSION_REQUEST_CODE
      );
    }
  }

thanks it help me, i just need to send data to hc-05 bluetooth don't need to post in google play store and it work

Thanks Taifun for the inputs.
But I feel the MIT should have the solution inbuilt for this issue.

BTReadWrite_2.aia (300.3 KB)

Summary

But, isn't this for the BLE and not for Classic Bluetooth??

Hc-05 is classic BT indeed. But both BT versions could use some more attention.

1 Like

I was referring to this app:

Apparently I've slowly lost track of what this is all about. No wonder after more than 120 posts. :upside_down_face:

Try this one (on Android 12+) → Companion & APK:
BluetoothClient_perm.aia (9.8 KB)

Blocks

And post screenshots after running Companion & APK.

Companion gets disconnected on its own after few seconds.
Screenshots of apk on phone as below,

Companion should look like this:

grafik

Try logcat to find out more

Taifun

Hi Anke.

seems that I have the same problem as Madhav, so I tried to run Your BluetoothClient_perm.aia

Below you can find a screenshot after running app.

Then I add a simple block to connect with my Bluetooth module HC-05 (Classic Bluetooth), shown below

block

When trying to connect with my HC-05 module that is available on the list with BT devices, I'm getting the same result/error as in all my application that was working a couple of weeks ago. Error shown bellow.

error

Is there any solution to this issue? What I'm doing wrong when trying to establish the connection (basing on .aia that you shared) ? Thank you in advance.

This appears to be a common issue with Xiaomi's Bluetooth implementation in Android 12, as it has been reported a number of times on StackOverflow (e.g., 1). We are discussing next steps to take in this regard.