Search code examples
androidpush-notificationgeolocationandroid-location

How to change location intervals with something like PUSH notifications


My app is able to track the user even if the app is in background or killed and send the currents lat and long to the server. I am using FusedLocationApi for this with a PendingIntent. My question is how can i change the interval of LocationRequest if my app is not running in foreground ?

I want to do something like catch the PUSH notification which firebase provide and then change this intervals, but it's not possible.

It would drain too much battery if i set the intervals (setInterval,setFastestInterval and setPriority) to the most frecuency and HIGH_ACCURACY and only catch in the server some of this request, and then when i want to get more frecuency, catch all the location requests?

Is it possible to avoid making the client (the user smartphone) work like a server that wait for a notification, like firebase?

EDIT: What i'm trying it seems to work but i still have the problem of comunication. I create a service and 2 differents types of API FusedLocationServices and 1 work at the moment and the other just wait for a signal from the server to start sending location... And that's exactly what i want to know how to do in a good way. How to listening to the server continuously ?? There exists a way like the onMessageReceived of firebase??


Solution

  • OK, i could handle this issue as i say, creating 2 differents LocationRequest, one running all the time when opening the app the first time with the necessary configuration and the other is created where i implement the onMessageReceived of firebase. I have to send a POST data-message (i use POSTMAN for this) to be sure that onMessageReceived is called and that's it!