Android not receiving location updates when screen is locked
Asked Answered
S

1

10

My app has to track the user continuously. For that I have a LocationListener which is supposed to receive location updates continuously. The issue is when the screen is turned off, it does not receive any updates.

I have tried adding a partial wake lock:

mLocationRequest = LocationRequest.create();
        mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);
        mLocationClient = new LocationClient(ADS.getAppContext(), new LocationGatherer(), new LocationGatherer());
        mLocationClient.connect();
        PowerManager pm = (PowerManager) ADS.getAppContext().getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
        wl.acquire();

But it still does not receive updates.

Saguache answered 4/3, 2014 at 8:18 Comment(3)
Take a look here It should help you outGers
Already answered here Link to answer having complete codeStrudel
Already answered here Link to answer having complete codeStrudel
K
3

Just bumped into the same problem. I too had the same code though it was within a Service. Strangely it did not work. Plugged in to my Laptop and ran a command mentioned in Android app high CPU usage, no services or wakelocks:

adb shell dumpsys power |grep -i wake

All of a sudden, location updates started arriving (the power button had been pressed and the screen was off).

I really have no clue as to what might have been the problem but that solved it for me.

As of now, receiving location updates even when the screen is turned off.

Kindling answered 9/9, 2015 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.