FusedLocationApi.requestLocationUpdates()在一段时间后停止间隔请求
问题描述:
此问题涉及我正在开发的Android应用程序。我正在使用Android版本7测试真实手机。FusedLocationApi.requestLocationUpdates()在一段时间后停止间隔请求
我希望FusedLocationApi以15分钟的间隔请求GPS位置。
当应用程序在前台并且屏幕开启时,GPS请求会按预期发生。
当应用程序最小化并且手机处于睡眠状态时,更新按预期进行一到两个小时,然后逐渐减少并完全停止。看起来,小振动或简单地打开屏幕(应用程序仍然在后台)会触发GPS更新。
// Request frequent location updates.
Intent locationUpdateIntent = new Intent(this, StoreLocationService.class);
locationUpdateIntent.setAction(StoreLocationService.ACTION_LOCATION_UPDATE);
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(15 * 60 * 1000); // 15 minutes
locationRequest.setFastestInterval(15 * 60 * 1000); // 15 minutes
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, locationRequest,
PendingIntent.getService(this, 0, locationUpdateIntent, 0));
答
我认为这是只是因为休眠模式,谷歌推出休眠模式这是你的后台服务之交这是使用互联网或网络,休眠模式被激活时,您的设备会约3〜5分钟理想的或处于待机模式(意味着您关闭屏幕没有任何使用互联网或网络的应用程序)。
这似乎是它。 https://developer.android.com/training/monitoring-device-state/doze-standby.html – paperduck