好的,所以基本上我想开始监听来自 a 的单个更新BroadcastReceiver
,并且由于某种原因,所有提供程序都被禁止访问。这是代码片段
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...
我猜问题是我从 a 调用所有这些BroadcastReceiver
,但我尝试从其他地方传递它的上下文。是否无法从 访问 LocationManager BroadcastReceiver
?