Android Question Problems with sending location when the app is in the background (FusedLocationProvider)

jose luis gudino

Active Member
Licensed User
Longtime User
Hello everyone.
I have a query that worries me.

Which is the exact way to send the location while in the background. In previous times, sending the location was extremely simple. Now I haven't made it.

I used a phone with an old version of android 9 and it worked perfectly. install the same program on a phone with android 11, and it stopped working.

My question is: may or may not send in the background at present?. I have done all the examples and I do not get the solution

Thank you all
 

DonManfred

Expert
Licensed User
Longtime User

Not sure if it still a working solution. I read often about the same problem. You need to try
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Android is more restrictive with every update.
In the DonManfred link you have this advice, have you do this?

There is a new requirement in Android 10+ devices.
In order for the location tracking to continue working in the background, if the user chooses the "allow while app is open" permission option we need to add this line to the manifest editor:
B4X:
SetServiceAttribute(Tracker, android:foregroundServiceType, "location")
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Android is more restrictive with every update.
In the DonManfred link you have this advice, have you do this?

There is a new requirement in Android 10+ devices.
In order for the location tracking to continue working in the background, if the user chooses the "allow while app is open" permission option we need to add this line to the manifest editor:
B4X:
SetServiceAttribute(Tracker, android:foregroundServiceType, "location")
Yes,
You should read the new restrictions and procedures to follow on the Android developer website.
 
Upvote 0

jose luis gudino

Active Member
Licensed User
Longtime User

Not sure if it still a working solution. I read often about the same problem. You need to try
Hello, thanks for your contribution . I already tried it. but unfortunately it didn't work
 
Upvote 0

jose luis gudino

Active Member
Licensed User
Longtime User
Android es más restrictivo con cada actualización.
En el enlace de DonManfred tienes este consejo, ¿has hecho esto?

Hay un nuevo requisito en los dispositivos Android 10+.
Para que el seguimiento de ubicación continúe funcionando en segundo plano, si el usuario elige la opción de permiso "permitir mientras la aplicación está abierta", debemos agregar esta línea al editor de manifiesto:
[código]
SetServiceAttribute(Tracker, android:foregroundServiceType, "ubicación")
[/código]
Android is more restrictive with every update.
In the DonManfred link you have this advice, have you do this?

There is a new requirement in Android 10+ devices.
In order for the location tracking to continue working in the background, if the user chooses the "allow while app is open" permission option we need to add this line to the manifest editor:
B4X:
SetServiceAttribute(Tracker, android:foregroundServiceType, "location")
Thanks jose, I've already tried it and nothing. It's like it stopped working.
As I mentioned before, on a phone with android version 9 it works perfectly, I have even written that in the manifest and nothing does not work
 
Upvote 0

jose luis gudino

Active Member
Licensed User
Longtime User
Hi.
I would really like to know if this is already a definite android restriction or if there is a solution.
to see which option to take.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
I remember there is a very helpful thread from a forum member where he was testing a lot of things with services and differents versions of android, but I can't find it. Maybe was @Sandman or @Mahares ? Not sure.

Anyway, if you test some apps that runs in background for long time, now it shows you some tips before redirecting you to the permission settings (i.e. Ignore app from battery optimization, etc...)

Some post maybe helpful:

 
Upvote 0

jose luis gudino

Active Member
Licensed User
Longtime User
I remember there is a very helpful thread from a forum member where he was testing a lot of things with services and differents versions of android, but I can't find it. Maybe was @Sandman or @Mahares ? Not sure.

Anyway, if you test some apps that runs in background for long time, now it shows you some tips before redirecting you to the permission settings (i.e. Ignore app from battery optimization, etc...)

Some post maybe helpful:

Jose, super grateful, for your time and for your interest in helping me solve this problem that is serious for me, since I have an app which is very important to use location sending in the background, I will read the information and I tell you if it works for me
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Nothing!, it did not work, I think that this topic is more complex than we think
Have you tried to set "No restrictions" to the Battery optimization of the app?
Something like
1668062435161.png
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi,

Its works... its NOT a NICE code have a lot "test" code.

Does NOT work for next day scheduling, when user force close the app.

I'm very busy and I hope someone put it in a decent way

Regards

Edgar
 

Attachments

  • Test_GPS.zip
    72.8 KB · Views: 109
Upvote 0

jose luis gudino

Active Member
Licensed User
Longtime User
Can you tell us about the process you use to capture the GPS location in the background (FusedLocationProvider)?

I have read the links you recommend?
another and watch the video
Hello TILogistic, thanks for providing a possible solution to the problem. Yes indeed, I use FusedLocationProvider.
I have removed all the code and I have left only the base code (the one that appears in the demos in its most recent version of FusedLocationProvider)
but nothing, I remember that the same code had been working for me for a year without any problem. but from a while ago it didn't work anymore.
 
Upvote 0

jose luis gudino

Active Member
Licensed User
Longtime User
Have you tried to set "No restrictions" to the Battery optimization of the app?
Something like
View attachment 135844
I have already tried this option and it does not work: the problem is basically: We have a service which records the location, the problem is that when calling "waze" in an intent ,the application goes to the background and immediately stops send position, when closing waze and returning to the foreground once it starts sending correctly
 
Last edited:
Upvote 0

jose luis gudino

Active Member
Licensed User
Longtime User
I explain in more detail:
the problem is basically: We have a service which records the location perfectly, the problem is that when calling "waze" in an INTENT the application goes to the background and immediately stops sending position, when closing waze and resume the foreground once starts sending successfully
 
Upvote 0
Top