屏幕锁定时Android未收到位置更新

问题描述 投票:9回答:1

我的应用必须持续跟踪用户。为此我有一个LocationListener应该连续接收位置更新。问题是当屏幕关闭时,它不会收到任何更新。

我试过添加一个部分唤醒锁:

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();

但它仍然没有收到更新。

android google-play-services wakelock locationlistener
1个回答
3
投票

刚碰到同样的问题。虽然它在服务中,但我也有相同的代码。奇怪的是它不起作用。插入我的笔记本电脑并运行Android app high CPU usage, no services or wakelocks中提到的命令:

adb shell dumpsys power |grep -i wake

突然,位置更新开始到达(按下电源按钮,屏幕关闭)。

我真的不知道可能是什么问题,但这解决了我。

截至目前,即使屏幕关闭,也会接收位置更新。

© www.soinside.com 2019 - 2024. All rights reserved.