电池优化白名单不会阻止推迟使用我的应用的打盹
问题描述:
我的应用每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));
答
白名单允许网络,但仍然阻挡了某些CPU的活动。使用setAlarmAndAllowWhileIdle()为白名单应用程序授予CPU使用权。
更多选项本文档中提到: