Android permissions - BLE - Android 12

What I meant was this: (I'm not sure if this is the right way to paste my blocks)
I started with this when I first got the permission error:
image
I then added the 'ask for permission':
image
This produced the request for permission but it also didn't connect since I hadn't answered the request yet. I then answered the request and put the connect part in after the permission was granted:
image
This didn't work since I believe what happened was that I had gave it permission the time before so that since the connecting part was buried in the 'if' statement, it didn't run. It seems that the permission is 'already on file' and doesn't have to be repeated.
I went back to the original version, added the BT Client component, and now everything is OK.

BluetoothLE.StartScanning can only be executed after permission BLUETOOTH_SCAN has been granted. So do it like this:

... and this:

Uninstall the previous app, build the new APK (with my blocks), install it and try.

Hi to all
I'm trying the workaround suggest from Anke and this seems work fine on Android 12, but nt work on old android version. For Example in 8.0 (samsung Galaxy S7) on start app (call screen AskForPermssion) show error like:
"Error 908:The permission BLUETOOTH_CONNECT has been denied. Please enable it in the Settings app".
Anyone have the same problem?
I'm trying to turn around the error detecting the version of anroid and skipping the woraround above, but i think is better patch the extension

Show your blocks (and post the aia).

See here:

I'm using your aia sample Android10BLETest_copy3.aia
now i will try to understand what you have replyed.

Many Many thanks

Thanks for your reply
i'm not understand if we need to detect android version and set different permission

I'm in trouble
i have decompiled apk and open the AndroidManifest.xml
the permission for BLUETOOTH, ACCESS_FINE_LOCATION is there

i have tryed to add ACCESS_COARSE_LOCATION and recompile apk ,but the error is the same.
is there a wa to be the app compatible from 8 to 12 android version?

thanks, i will try
I did not know the getApiLevel extension, good.

Many many thanks Anke
for me works both with 8 and 12 android version with these little difference of block

and this is the aia project
AndroidBLETest_v8_12.aia (191.2 KB)

at screen.initialize i need to ask for permission only if newer android version.

I hope my solution could help other developer.
the FineLocation seems to be already in permission.

I hope also a new release of the extension with compatibility.

You could also leverage Screen1.PlatformVersion, which would need to be compared to 12.0, but it would allow you to do this in a way that doesn't require extensions. The only caveat technically would be one of the 4.2.x versions which won't coerce to numbers, but since the BLE extension requires Android 5.0 or higher this shouldn't be an issue.

I checked it now on Android 9 and removed my post.
I'll post a new aia tomorrow.

It didn't work. If I am right, you only have to give it (the phone in question) permission one time. After that, it doesn't ask for it again. I think that's why nothing happens when you bury the connection process in an 'if' statement that it doesn't get to.

Here's what I used.


Apparently it doesn't get to the Start Scanning part.

I'm not sure if I understood correctly. There are several Android verisons like 5.x, 7.x, 8.x.
Apart from that, the minSdkVersion is not 21 when using the BLE extension:

grafik

Yes, ACCESS_FINE_LOCATION is automatically requested with Bluetooth.StartScanning.

1 Like

I have tested on other smartphone (os 11) and the error is there again.
I will try to investigare showing the versioncode.
adding

version code detect on smartphone:
android 11 (redme note 9) = versioncode 30
android 12 (samsung s10p) = versioncode 31
I will try with trigger at 30 inside of 28

Try this one (tested on Android 9, 10, 11, 12):
BLE_permissions_allAndroidVersions.aia (191.7 KB)

Blocks

2 Likes

The > operator will coerce the strings to numbers so what I proposed will work so long as the version number is specified as major.minor and minor never goes above 10, but 4.2.2 is not a number so the block will raise an error.

While the BLE extension does not force a minSdk, the logic of the component is written such that its blocks do nothing on versions less than 21. We didn't want to surprise people who added the BLE extension to their app with the increase to minSdk 21, especially if the BLE functionality might be optional. Of course, this decision made way more sense when BLE first came out and most phones didn't support it yet.