【发布时间】:2017-09-13 03:07:10
【问题描述】:
我的应用每 15 分钟向我的服务器发送一次 GPS 位置数据。此功能是应用的核心目的。
但是,当手机关闭且未使用时,GPS 记录会逐渐减少。 GPS 记录之间的时间间隔是 15 分钟,然后是 1 小时、2 小时、4 小时、6 小时,然后当我移动手机或打开手机时又回到 15 分钟。
这似乎是由于 Android 6 中引入的打盹模式所致。我将该应用添加到了电池优化白名单中,但这并没有什么不同,despite the documentation claiming otherwise。
- 为什么白名单在这种情况下没有帮助?
-
我应该怎么做? Wakelock 会定期延迟,从而防止打瞌睡吗?
// Request frequent location updates. Intent locationUpdateIntent = new Intent(this, StoreLocationService.class); locationUpdateIntent.setAction(MyAwesomeActionName); 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 android-doze android-doze-and-standby