我正在测试一个应用程序,选择当前位置,并在小部件上进行筛选。我正在使用这个功能,但当我尝试将精度改为HIGH时,一切都崩溃了!
private void startListening(){
AppLog.logString("Service.startListening()");
final Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
final String bestProvider = manager.getBestProvider(criteria, true);
if (bestProvider != null && bestProvider.length() > 0) {
manager.requestLocationUpdates(bestProvider, 500, 10, listener);
}
else {
final List<String> providers = manager.getProviders(true);
for (final String provider : providers) {
manager.requestLocationUpdates(provider, 500, 10, listener);
}
}
}
答案 0 :(得分:1)
将其添加到AndroidManigest.xml文件中:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>