Need Help In Bluetooth Permission for an app on Android 12

The Xiaomi 13 Pro has a BLE v5.3 chip
The Sony Xperia 5 IV has a BLE v5.2 chip

So both very up-to-date

This is not an issue of the hardware stack. The issue is in the software stack. We followed the Google guidance on the matter and it worked when we tested it on Google and Samsung devices, which is what we generally use when we conduct our workshops. I also verified by looking at the Android 12 sources from the AOSP repository and the various methods we use in the BluetoothClient are annotated correctly regarding permissions. The fact that some manufacturers' builds of Android 12 are asking for the old Bluetooth permission indicates a problem from their end, and my development experiences suggests that it was likely a poorly resolved merge conflict, resulting in the removed permissions being restored incorrectly.

In the meantime, we've relaxed the maxSdkVersion constraints for these two permissions on ai2-test.appinventor.mit.edu. Folks encountering errors for android.permission.BLUETOOTH on Android 12 can try loading and building their projects there.

1 Like

I had no luck in the test-platform either.
error

This is my prg:


(The working project from 3 months ago didn't ask for the Bluetooth_scan, only Bluetooth_connect; I don't need the scan functionality, just trying different things to make it work as before, I only need to edit the text of some lables otherwise the working build from last year would be ok for me)

BorrmaskinHMI2.aia (77.2 KB)

Only builds will have the problem fixed. Did you try to build your app?

Yes I buiilt it to an apk and downloaded to phone via qr-code.
When building in the test environment I get a couple of warnings about it's a dangerous app, do you really want to install etc.

I get two questions about permissions when the app is started the first time. "Do you want to allow finding, connecting and determine relative position to devices close", and then the same question one more time. (My phone is in swedish so i'm not sure about exact wording)
I allow that, but then when I pick a device to connect I get the lack of permission Bluetooth error.

Try this test APK and post a screenshot after the first run:

Screenshot from a Pixel 4XL, Android 13

Hi Patton, I tried this. Built the app, downloaded and installed on my Xiaomi Note10 Pro. But the issue still persists. Lacks Permission android.permission.BLUETOOTH

Hi Anke, may i know what are we testing by running this app. It runs fine on my phone without throwing any error while selecting the desired bluetooth. But it doesnt connect to the bluetooth. But what does it prove.

It should show that both permissions are granted correctly. So please post a screenshot.

Anke, pls see post 122. I had posted the screenshots couple of days ago.

Blockquote

I mean this one (post #137):

And did you test it on the AI2 test server: https://ai2-test.appinventor.mit.edu/ ?

Can you pls send the .aia file

Hi all.
Just to confirm Madhav case. On my side, building the app in a test environment and installing it on mobile also lead to the same resoult.

Scren after running the app

Then after trying to connect to one of the device from list

As mentioned earlier, I'm working on Mi 11T Pro and to connect with the BT device, I add this simple block to the app
block

Anke's test (apk) above is working nice. The error in my app shows up when connecting.

After reading the whole thread I see that there is no clear solution. I had a functional app on my device, I updated it and when I downloaded it again, the problem mentioned here appears and I did not find any solution. What a pity, hopefully it will be solved soon.


This is a picture of the error.

Hi Fabio,

If you do not wish to place the app on play store, then there is a solution to this issue. Pls see my post no 105 on this thread.

Yes I actually tried. But it appears a problem with java when I try to open de APK on the program. Later y will publish a screenshot, but I think it's not mi problem because I was following your steps, but thanks anyway.

Here is the problem, I just dowloaded the apk from MIT as you say. Open the program and select the file, then the app shows me this error:


And with this problem i cant open contents to continue following your steps.

Hope the JAVA is installed and is updated

I'm also encountering the same problem "UID 10718 / PID 5169 lacks permission android.permission.BLUETOOTH". As a Smartphone, I'm using a Xiaomi Poco X3 with Android 12 and MIUI 13. Till almost 18th February (also when this discussion was created) everything was working fine without a problem. Then maybe MIT had an update? After that, I encountered the error above.
I gave the app all permissions I need (it was working though), so I looked at the AndroidManifest.xml (see Post #107) from my working apk (before 18th February) and the new build apk from today. Both xml-files are almost the same, but with two differences.
On my working apk all permissions look like this:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

And on the new apk the permissions are given like this:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:maxSdkVersion="30" android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:maxSdkVersion="30" android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

In the new apk, the permissions "BLUETOOTH_ADMIN" and "BLUETOOTH" are set to the maxSdkVersion 30. After I deleted those both, I installed the apk and it was working for me again. So these both maxSdkVersions are causing my problem.

1 Like