3
如何減少我的應用程序中的用電量?我可以用什麼代碼來實現這個?如何降低基於位置的Android應用程序的用電量?
如何減少我的應用程序中的用電量?我可以用什麼代碼來實現這個?如何降低基於位置的Android應用程序的用電量?
在嘗試獲取位置信息時,有幾種不同的方法可以降低使用的功率。
使用last known location而不是嘗試確定當前位置。
// Get a Location Manager
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Try to get the last GPS based location
Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
// Fall back to cell tower based location if no prior GPS location
if (l == null) {
l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
使用較便宜的位置提供商。您可以直接選擇LocationManager.NETWORK_PROVIDER或指定您關心的criteria,然後讓Android告訴您要使用哪個位置提供程序。
// Select the criteria you care about
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_COARSE);
c.setPowerRequirement(Criteria.POWER_LOW);
// Let the system tell you what provider you should use for your criteria
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String p = lm.getBestProvider(c, true);
// Call other Location Manager functions using the above provider...
非常感謝我在50%實現 – Narasimha 2010-04-21 11:40:07
在我的應用程序的電池使用電池使用率和內存使用情況及其適用的另一種方式 – Narasimha 2010-04-22 05:37:46