简体   繁体   中英

Android not receiving location updates when screen is locked

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM