FusedLocationApi.requestLocationUpdates()在一段时间后停止间隔请求

时间:2017-09-07 04:04:57

标签: android gps fusedlocationproviderapi

这个问题与我正在开发的Android应用有关。我正在使用Android版本7的真实手机进行测试。

我希望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));

1 个答案:

答案 0 :(得分:1)

我认为这只是因为DOZE模式,谷歌引入DOZE模式,这是你的后台服务,使用互联网或网络,当你的设备大约3到5分钟理想或待机时,DOZE模式是活动的模式(意味着您关闭屏幕,没有任何使用互联网或网络的应用程序)。

相关问题