好吧,所以基本上我想開始監聽BroadcastReceiver
的單個更新,出於某種原因,所有提供程序都禁止訪問。這裏是代碼片段LocationManager getProviders(true)不返回提供商
LocationManager locationManager = (LocationManager)
context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setPowerRequirement(Criteria.POWER_LOW);
String majorProvider = locationManager.getBestProvider(criteria, true);
Log.d("location test", "major provider " + majorProvider);
List<String> allProviders = locationManager.getAllProviders();
for(int i=0; i < allProviders.size();i++) {
Log.d("location test", "provider " + i + ": " + allProviders.get(i));
}
Log.d("location test", "enabled...");
allProviders = locationManager.getProviders(true);
for(int i=0; i < allProviders.size();i++) {
Log.d("location test", "enabled provider " + i + ": " + allProviders.get(i));
}
和我的logcat結果
04-09 11:23:35.763: D/location test(32576): major provider null
04-09 11:23:35.763: D/location test(32576): provider 0: network
04-09 11:23:35.763: D/location test(32576): provider 1: passive
04-09 11:23:35.763: D/location test(32576): provider 2: gps
04-09 11:23:35.763: D/location test(32576): enabled...
我猜測的問題是,我從BroadcastReceiver
呼籲所有這一切,但我想通過它的上下文從別的地方。是否可以從BroadcastReceiver
訪問LocationManager?
所有供應商都啓用或不是...? – ngesh 2012-04-09 08:35:21
@sandy他們都被禁用,它只是一個被遺忘的權限 – MikeIsrael 2012-04-09 08:36:40