location-samples
location-samples copied to clipboard
LocationUpdatesForegroundService not working while phone is idle / locked / dozing
Hi there,
I downloaded the examples and compiled the "LocationUpdatesForegroundService" one into several devices to try it out.
I was hoping the location updates would keep on happening while the phone was locked (IE: in my pocket)" but unfortunately, I saw, that is not the case. A few seconds after locking it, it just stops updating or sometimes tracks the time wrongly.
I logged every update into a text file to check what was going on and make sure about it.
I've tried a million different things in order to get it to work while the phone is idle (alarms, pendingIntent callbacks, new threads, jobIntentServices...) based on everything I've been able to find online, but I just can't seem to find the way.
I'm not sure if the project is supposed to do such a thing or if it would be an additional kind of behaviour. In any case, I would be extremely thankful if someone could provide a solution or guide me into one. I'm kind of desperate at this point...
Thank you very much.
hi @CarlosCabarcos,
I unfortunately don't have a solution yet for you.
However could you test with the sharing feature of google maps?
It's seem to be doing what you're asking, so If maps work then you may need to post more information about the phone you're using ( Android 10?) and probably the change made.
hi @CarlosCabarcos, I unfortunately don't have a solution yet for you. However could you test with the sharing feature of google maps? It's seem to be doing what you're asking, so If maps work then you may need to post more information about the phone you're using ( Android 10?) and probably the change made.
Hi @Fraid. I'm not working with a single phone, I've tested it on several devices and they all fail :(. The google maps feature works fine, also, I've tried some other commercial apps that keep on doing work in the background while the phone is locked / idle and they work just fine, so the phones clearly have the capability of doing it. It's either not implemented in this example, or failing for some other reason...
From the sample without modification, on emulator with android 10. I don't have any issue....unless I force idle (adb shell dumpsys deviceidle force-idle
). So, could try on the emulator too (pixel 3a, android 10), does the notification get updated ?
You say, I put the phone in my pocket, but where you moving outside? Same for google maps, did you moved outside and see that the location was moving, from the second account you're sharing with?
Also i'm not the owner of this repo but I think you should state the device you're testing on at least one (Several samsung devices ? Several Android 9 ? ). Also does the other commercial app target the latest SDK ?
to resolve doze mode issue you can use workmanager like this: //creating a work request PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(UploadWorker.class, 15, TimeUnit.MINUTES) .build();
WorkManager.getInstance(MainActivity.this).enqueue(periodicWorkRequest);
.....................................................................................................
public class UploadWorker extends Worker {
private String TAG = "UploadWorker";
public UploadWorker(
@NonNull Context context,
@NonNull WorkerParameters params) {
super(context, params);
}
@Override
public Result doWork() {
uploadLocation();
return Result.success();
}
private void uploadLocation() {
// do your repeating task here
}
}
is it intended behavior that the location update stop working when device idle even with foreground service ?
Any update? Did anyone find any solution to foreground service not up and running in idle doze mode?
Any update? Did anyone find any solution to foreground service not up and running in idle doze mode?
None, unfortunately :(. Me and my colleague literally went crazy trying to solve this and in the end we had to give up and move on unto something else. There must be some way to do it, but we just couldn't find it.