GPS with Android 12

@d_Taraoa: I would be interested in seeing how this app performs for you. I tested it on a Pixel 3 running Android 12 and was able to get an accuracy as low as 4.288 m depending on my distance from nearby buildings. The Pixel 3 in question did not have a SIM card nor was it connected to Wifi, so the results should have been coming from the GPS alone.

LocationSensorTest.aia (2.9 KB)


When I install LocationSensorTest I get an error message
if I finish the installation it's ok

I have modified LocationSensorTest with the FineLocation permission, I have no error during the installation and everything is OK
the Accuracy is 3 or 4 m
it is better that locationSensor is disabled in designer (I don't understand why) and to activate it in the initialization of the screen only
The GPS icon is in the status bar
and everything is correct.
I will modify my other applications and I will keep you informed
thank you so much

My Blocks and LocationSensorTest_2

LocationSensorTest_2.aia (3.0 KB)

1 Like

Yes, but not only on Android 12. I get the same error on Android 11 and 12 (Companion).
(But both permissions are declared in the Manifest of the Companion app.)

I did some tests on this rainy Sunday
the finelocation permission works if:
LocationSensor is disabled in designer
The permission request must not be in the initialization of the screen (otherwise I get a temporary permission, if I close the application the permission is lost)
I use a timer to ask for permission after initialization
we can also use a button
I tested with android 12 and android 8 it's ok

Some details:
TimeInterval is at least 5 seconds (battery protection?)
I have an empty list in the suppliers
the status changed function does not return any results

LocSensorInit.aia (3.5 KB)


Has you tested to asign the ProviderName = "gps" and nothing more (lets ProviderLocked = false)?. In this case you don't need to ask and manage the Fine-Permission. In my case it runs well with Android 12.

it's very simple and it works, I checked the permissions are granted
Thank you

My LG G8 thinkQ just updated its OS to Android 12 then GPS on my app showed weird output. Now I have to start fixing this problem while I'm not sure where to begin. I just share a screenshot how this problem serious. Now just let you know, GPS works well on my app before Android 12 update.

What is weird Bob? It is impossible to tell from the image you posted. Please explain.
you might post an aia or your Blocks. Impossible to provide advice without sharing code.

Do you have a screen image prior to upgrading to Android 12 to share?

Black line in a screenshot is a route my bicycle moved. I just rode straight from bottom end point of line to north but output line drew weirdly while riding. and I read some comment of getting the ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions in a single runtime request. I don't understand 'a single runtime request'. I assume that means like add two blocks of 'call screen1.AskForPermission permissionName: Permission FineLocaiton' and 'call ... Permission CoarseLocaiton' block. Maybe I'm wrong...
riderLang_copy.aia (6.0 MB)

감사합니다 – Kam -sa -ham-ni -da Bob.

Looks like a great app.

I can start a 'ride' on my Android 8.1 but can't figure out how to display the map. Do I have to wait until the app passes a certain distance threshold.


You can open map with pin icon button left of km and Badges buttons. Thx to say that... :slight_smile:

1 Like

Thanks. I will look later.

You might try

I am busy at the moment but will try your suggestion in a while.

In the meanwhile, you might try the aia code @d_Taraoa posted in about post #30 to see if his method works on your Android.

1 Like

See here Solicita permisos de ubicación  |  Sensors and location  |  Android Developers

User can grant only approximate location

On Android 12 (API level 31) or higher, users can request that your app retrieve only approximate location information, even when your app requests the ACCESS_FINE_LOCATION runtime permission.

To handle this potential user behavior, don't request the ACCESS_FINE_LOCATION permission by itself. Instead, request both the ACCESS_FINE_LOCATION permission and the ACCESS_COARSE_LOCATION permission in a single runtime request. If you try to request only ACCESS_FINE_LOCATION , the system ignores the request on some releases of Android 12. If your app targets Android 12 or higher, the system logs the following error message in Logcat:


it looks like the MIT App Inventor team @ewpatton will have to provide a solution, so both permissions can be requested in a single runtime event… alternatively someone could write a short extension for that…


1 Like

I tried these two. I will check both outside tomorrow if GPS works or not.

Interesting that this seems to be applied to all apps regardless of the target SDK version. Typically, if an app targets an earlier version of Android, the semantics for that version are applied. Google Play requires starting today that new apps target Android 12, and in November the same for updated apps, but that's a policy rule enforced by the store and shouldn't affect apps installed directly to the device otherwise. The COARSE/FINE permission change will be in the 2.65 companion update later this month to address Android 12 compatibility. In the meantime, you can try loading the companion from the ai2-test server and see if your LocationSensor behaves correctly since that server includes the pending changes for Android 12.


Added two AskForPermission doesn't work but, the aia code @d_Taraoa posted works. So I attached some steps from this code to mine then GPS went to be as normal.

  1. AskForPermission moved to Clock from Screen1.initialize
  2. Add LocationSensor1.ProviderLocked to true, LocationSensor1.ProviderName to gps in the Screen1.PermissionGranted block.

Thanks for guiding me.


ok, great... thank you for letting us know...
I will move the solution marker from your contribution to the real solution, which is post #31

Left: targetSdk: 30 (Android 11) │ right: targetSdk: 31 (Android 12, built on AI2 test server):

Tested on a device with Android 12 (APK).

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.