我开发了一个Android应用程序,用于检查位置更新并在一段时间后将位置数据发送到服务器。我测试了两种方法;一个使用Google location apI,另一个使用Android服务。但这两款应用都耗费了太多电池。我需要优化电池的使用,以便用户可以根据需要使用该应用程序。
有几个应用程序一直跟踪我们的位置,从不妨碍电池;例如endomondo,Facebook等。我特别想提到endomondo,因为它在工作时真的很好用。
任何人都可以建议我为Android应用程序实现位置感知的最佳方法吗?
如何让我的应用像endomondo或类似的位置感知应用?
请建议我更好的方法。
提前致谢。
答案 0 :(得分:0)
您是否尝试通过检查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;
}
}