Need Help In Bluetooth Permission for an app on Android 12

@Ghica @Anke @ChrisWard
I am trying to use applications provided by @Ghica (reference: App Inventor, Micro:bit and UART)

It seems like it does not support Android 12, as blocks for BLUETOOTH_CONNECT and BLUETOOTH SCAN are missing.

I added the blocks for the same in the mit app.

But getting errors:


Refer to the updated mit app:
BTReadWrite.aia (296.0 KB)

Help to resolve these issues for BT connectivity.

Android mobile version 12

Thanks in advance.

And again and again and again ... :woman_shrugging:
Use the current version of the BLE extension!

See post #73.

BLE version

Uhhh Ohhh!

Sorry I missed out on updating BLE extension.

Thanks for the response.

I will keep this in mind... ( :wink: :wink:)

Sorry, I may be stupid, I intended to update my tutorial this morning, but where is the updated extension??

Another point, you may wonder what the webviewer running JavaScript is for in my example. It is needed because there is still no way to convert the Ascii you recieve from the micro:bit to characters AppInventor can handle. So, if you want to display your text in your label, you better use this.

1 Like

I tried this (and removed the Location permission in the Manifest) to get rid of the Location permission / request, but it doesn't seem to work (on Android 12+):

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
                 android:usesPermissionFlags="neverForLocation" />

I am not really sure what I can do, except buying a new phone :frowning:
But the real question is what is @Sudarshan_Gupta able to do.

And again, he should use the current BLE version.

Hi Mohit, I was able to solve the problem of Bluetooth Permission error.

  1. Build the APK file from your project in MIT APP inventor.
  2. Open the AndroidManifest.xml file to modify the permissions.
  3. Delete all permissions related to BLUETOOTH and add 3 lines.

  1. Save the AndroidManifest.xml file with above changes.
  2. Rebuild the APK file.

NOTE:

  1. How to view the AndroidManifest.xml?
    ------ Download APK Studio Editor from the link Download APK Editor for PC and Mac – APK Editor Studio
    ------ Open APK Studio Editor and Open the APK file.
    ------ Click on the "Open Contents" tab
    ------ Folder will be opened and "AndroidManifest.xml" file can be seen.

  2. How to Edit AndroidManifest.xml file?
    ------ Open the AndroidManifest.xml using any of the text editor.
    ------ Delete the lines related to Bluetooth related permissions.
    ------ Paste the below lines and save the changes.

  1. How to Rebuild the APK
    ------ After following the Step1 and Step2, On APK Studio Editor, Click on "SAVE APK"

Now, install the APK on mobile and Check the Bluetooth Permission Error Should be gone

3 Likes

Hi Madhav

I confirm that it s works for me . I changed the androidmanifest.xml , exactly as you perfectly explained us, with APK studio Editor .
I delete all line with mentionned bluetooth permission and changed at the beginning with your :

even if it is not necessary very pratical so far, many thanks to you

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