在相同的情况下,我们对设备每10分钟请求一次位置所花费的电量进行基准测试,该设备仅与WiFi连接。
首先将优先级设置为PRIORITY_BALANCED_POWER_ACCURACY,然后设置为PRIORITY_HIGH_ACCURACY。
令人惊讶的是,前者的耗电量与后者相同,如果不是更多的话。以下是电池使用情况的图表:


有人能解释一下这种行为吗?
发布于 2017-07-13 05:20:35
PRIORITY_HIGH_ACCURACY更倾向于使用GPS,而PRIORITY_BALANCED_POWER_ACCURACY更可能使用WIFI和蜂窝塔定位。
PRIORITY_BALANCED_POWER_ACCURACY (~100 m“块”精度)PRIORITY_HIGH_ACCURACY (以牺牲电池寿命为代价尽可能准确)
使用setInterval(long)和setFastestInterval(long)来节省电池寿命。示例:
private static final long INTERVAL = 60 * 1000;
private static final long FASTEST_INTERVAL = 5 * 1000;
private static final long DISPLACEMENT = 100;
private LocationRequest createLocationRequest(){
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
return mLocationRequest;
}Google在这里描述LocationRequest类:http://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html
https://stackoverflow.com/questions/31119580
复制相似问题