【发布时间】:2017-09-07 04:04:56
【问题描述】:
这个问题是关于我正在开发的 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));
【问题讨论】:
标签: android gps fusedlocationproviderapi