GPS with Android 12

How you request permissions might be the issue. Please show your Blocks showing how you request fine and coarse location,

Note

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.

It appears you are getting COARSE_LOCATION only.

see https://developer.android.com/training/location/permissions#approximate-request

@ewpatton might be able to help regarding how to request simultaneous permissions.

Por la pequeña experiencia que tengo con GPS, no creo mucho en el dato de precisión que indica la aplicación . Como ves en la imagen yo lo he cargado en un teléfono

Android 5.1 y seguro que esa precisión no es correcta . No puede dar 2 mts de error . No sé de donde saca ese dato, pero por lo que yo conozco esto depende mas del numero de satélites que ve y la ubicación que tienen entre ellos y con eso calcula unos parámetros que se llaman HDOP y VDOP que son un factor que multiplica al error para calcular los errores teóricos horizontalmente y verticalmente . Cualquier GPS de los que conozco el error esta por encima de los 3 mts a los que tendrías que aplicar el factor correspondiente en cada momento . El GPS de mi teléfono está por encima de ese error seguro .
Mi pregunta es : ¿estas en un interior o fuera en la calle? , ¿en el campo en zona sin casas grandes , mucho cemento ? todo eso influye en la precisión. ¿puedes saber cuantos satélites estas cogiendo el GPS? si no tienes al menos 8 o 9 no llegaras a tener estos factores cerca de 1 que sería lo ideal para tener la mejor precisión posible.
Espero que te sirva de ayuda.

Saludos.

That is an image from a 5.1 Android and your existing app with fine/coarse location settings requested?

Using the Location Sensor addresses some of your questions Miguel.

An Accuracy of 2 m is possible. What may be happening with your 5.1 Android is the phone is possibly using both the gps and WIFI simultaneously when you set Coarse and Fine on some devices lower than Android 12. The LocationChanged event does not trip (fire) because a location change is not reported. Your Android 8 and 11 displayed Accuracy values more typical. Did you collect that data indoors or out. Take the test 5.1 phone outside and see what it reports (no wifi and a clear sky so the gps has an opportunity to achieve a new satellite fix) and let us know. Is there a difference?
The Accuracy of any single satellite fix depends on lots of factors ( GPS.gov: GPS Accuracy ) and not necessarily the number of satellites. Accuracy also depends where the satellites are in relation to the phone (far away or close or overhead or near the horizon).

Sorry, this is not true Miquel. Improved gps precision depends on how many constellations and channels the gps receiver is able to receive. It is not Android version dependant. What happens depends on the Android gps hardware. The MIT LocationSensor control is only capable of interpreting the GPS satellite information as far as I am aware. There are extensions that can interpret the GPS, GLONASS, GALILEO, BEIDOU, QZSS AND IRNSS and provide more precise location information than the LocationSensor depending on the availability of required gps hardware in the device..

Muchas gracias por tu información ,si es cierto que había oído sobre la mejora del calculo por conexión con otros GPS de referencia mejorando la precisión del GPS . Al parecer pueden conseguir precisiones de centímetros . Pero no pensé que esto era utilizado de alguna forma por mi Android, parecía que esto estaba reservado a GPSs de coste elevado.
Con relación al numero de satélites es cierto que cuatro satélites si están suficientemente distantes parece que puede dar una precisión suficientemente buena , pero mi experiencia es que cuando las cosas mejoraban era cuando tenia 8 o 9 satélites . Posiblemente será desde mi ubicación lo condiciona el resultado.
De todas formas aunque me he salido un poco del tema principal , ( espero que me disculpéis ) agradezco esta información que estudiare detenidamente, por que es un tema que me interesa . He trabajado no desde el punto de vista de un GPS Android sino con equipos equipos externos mandado datos a Android para representarlo en mapas de google y esto me abre un nuevo campo de conocimiento.

Saludos.

Here is my conclusion:
with android 12 the APP application does not really activate the gps ,

the gps icon is not in the status bar ,

the GPS coordinates received certainly come from the 4G / 5G network, which explains the poor precision,
in airplane mode I am not receiving GPS coordinates,
with the other GPS applications everything is ok,
before the android 12 update everything is ok,

thank you all
wait and see .......

1 Like

It's possible that Android 12 is returning the list of providers in a different order than earlier versions of Android. App Inventor obtains the list of available providers that the system claims can perform as needed based on the time/distance criteria and then tries starting them in order. The first one to become active is used. This may mean that in earlier versions of Android a list like "gps", "network" was returned and now "network", "gps" is returned instead. I don't have an Android 12 device right now so I cannot confirm this.

You could try adding the following blocks to your Screen1.Initialize and see if it resolves the issue.

Edit: Note that you can also get a list of the available providers using the property of the same name.

2 Likes

Check your device Settings. It appears you have accidently turned off your Location setting.
I experienced something similar. When Location is off, you will find the behavior you noticed.

To get my Android 8.1 tablet working again, I turned the Location setting back on. Then to get the gps to work again, I had to reboot/restart the Android. :cry:

There also seems to be a permissions problem on Android 12. How does one set Coarse and Fine permissions simultaneously as in the Google advice linked in post #10 ?

Regarding your ProviderLocked, shouldn't that come after setting ProviderName to gps ?

I don't have an Android 12 either.

1 Like

As far as the LocationSensor is concerned, we ever only ask for FINE location (see here), which up until now has also always implied COARSE location. Further, App Inventor apps still target Android 11, not Android 12, so those requirements do not yet apply (they will go into effect for apps starting next summer). As part of our update to comply with Google policies next summer we will make the necessary changes for Android 12 "improvements."

1 Like

Thanks. That probably means that developers will be limited to using the gps in Android 12 devices in Coarse mode (per Google's developer advice to submit both Coarse and Fine permissions simultaneously). That seems to mean the default Location permission of Coarse will have to be used with the existing LocationSensor control until a later release of App Inventor, sometime within the next 8 to 9 months and gps performance will be degraded (based on how I read Google's Android Location restrictions). (See post # 8 )

Simply, use of the gps seems to be broken (degraded) on Android 12 devices for the foreseeable future w.r.t. App Inventor developers.

@d_Taraoa There might be a work around for you.

On Android 12 and higher, users can navigate to system settings to set the preferred location accuracy for any app, regardless of that app's target SDK version. This is true even when your app is installed on a device running Android 11 or lower, and then the user upgrades the device to Android 12 or higher.

5 posts were split to a new topic: Android 12 Migration

Thank you for these details, I have the explanation for my problem

2 posts were merged into an existing topic: Android 12 Migration

@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)

2 Likes

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.)

Hello
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)

2 Likes

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.