我已经开发了一个android应用程序,它可以检查位置更新,并在一定时间后将位置数据发送到服务器。我测试了两种方法;一种是使用Google location apI,另一种是使用Android服务。但这两款应用都太耗电了。我需要优化电池的使用,这样用户就可以根据需要使用应用程序。
有几个应用程序可以一直跟踪我们的位置,而且不会妨碍电池;例如endomondo,Facebook等。我特别想提到endomondo,因为它在工作时真的工作得很好。
有没有人能给我提个建议,让android应用实现位置感知的最好方法?
如何让我的应用程序像endomondo或类似的位置感知应用程序?
请建议我做这件事的更好方法。
提前谢谢。
发布于 2016-07-28 23:29:32
你有没有尝试过通过检查LocationManagar是否有足够好的位置来减少GPS位置跟踪?(也许是其他应用程序跟踪?)
例如:
private static Location bestLastKnownLocation(float minAccuracy, long maxAge, LocationManager mLocationManager) {
Location bestResult = null;
float bestAccuracy = Float.MAX_VALUE;
long bestAge = Long.MIN_VALUE;
List<String> matchingProviders = mLocationManager.getAllProviders();
for (String provider : matchingProviders) {
Location location = mLocationManager.getLastKnownLocation(provider);
if (location != null) {
float accuracy = location.getAccuracy();
long time = location.getTime();
if (accuracy < bestAccuracy) {
bestResult = location;
bestAccuracy = accuracy;
bestAge = time;
}
}
}
// Return best reading or null
if (bestAccuracy > minAccuracy || (System.currentTimeMillis() - bestAge) > maxAge) {
return null;
} else {
return bestResult;
}
}
https://stackoverflow.com/questions/38644699
复制相似问题