Beta version of BLE extension for Android 12 permission changes

Hmm. That is troubling because the Google documentation for Bluetooth permissions definitely does not read that way to me. It claims:

  1. If your app communicates with already-paired Bluetooth devices, declare the BLUETOOTH_CONNECT permission.

but when one scans for devices there's no guarantee that the found devices are even paired so the antecedent can't hold.

I'll try to build a very simple test app outside of App Inventor and poke around the AOSP to see if there's some additional insight to be had there.

[1] Bluetooth permissions  |  Connectivity  |  Android Developers


Permissions:

I think I have an idea of what is going on. Can you attach a copy of the stack trace from adb logcat?

I've uploaded a new version which should mitigate the issue.

1 Like

To where?
EDIT: Got it.

Yes, this works.
But the Location sensor has to be enabled (also on Android 12+), as I already mentioned (at least to find / list my devices).

1 Like

Maybe one can get rid of the Location permission on Android 12+ if this is declared in the Manifest:

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

I'll check it later ...

If you'd like to add that flag, you should be able to check the new design property "NoLocationNeeded". However, due to limitations in the App Inventor build system this won't result in the removal of the ACCESS_FINE_LOCATION permission in the Manifest, but it should stop the extension from asking for the permission at runtime.

Well, since I have to edit the manifest anyway, I might as well remove ACCESS_FINE_LOCATION there. At the moment, however, I also have the problem with my current work notebook that the "neverForLocation" flag is unknown in my APK Editor Studio version. It was probably added later by Google.

Unfortunately, the current APK Studio version cannot be installed on my ancient Win7 notebook. I'll have to try it on another Win10 PC or on my MacMini, later ..

Hi Evan - is anything being sorted out for the Bluetooth Classic issue?

Re: Need Help In Bluetooth Permission for an app on Android 12 - #97 by Madhav

That is about a Bluetooth Classic permission error but has got overwhelmed with the BLE issue. See post#97 from Madhav, the original Topic author.

Correct. The flags feature was something added for SDK 31 and needs a newer version of the build tools even for us to compile with it, so I expect many other tools will need to be updated to take it into account.

Hi Evan and Chris, I have figured out a way to solve this Bluetooth Classic Permission Issue.

  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

1 Like

Even with the latest version of apktool it is not possible to set compileSdkVersion=31:

It seems to be related to aapt2.exe (aapt.exe) - I'm not sure... :woman_shrugging: :thinking:
Please any tip/hint that might help?

If you set the targetSdkVersion=29 the app (APK) will not allowed by Google (in the Play Store). The minimum targetSdkVersion has to be 31.

BTW... (see here):

1 Like

Hi Evan,
Part of this release, what's the chance to fix the AdvertismentData block?
This module return null, seems it was never works.
I need it for some IOT class.

THX
Ziv

Hi Evan, hope your brain is suitably refreshed after your short break :grin:

Re my Post#20 in this topic:

To prevent the BLE Device List becoming so large it slows the Smartphone down or crashes the App, we need a new function that filters devices found and only adds them to the BLE Device List if a specific string exists.

i could use scan with @Anke 's way that set "scan block" dummy for get connect permission in running!

but still "advertising" is not working.

it showing always "false" in result.
can i make it working with any ways??

You are using Kodular. (You should ask there.)
Did you try it on AI2 too?

yes and tested with after get "connect" permission.
still giving "false"

blocks

i didn't use APK studio. must i?