基本的に、からの単一の更新のリッスンを開始したいのです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...
問題は、これをすべてから呼び出していることだと推測してBroadcastReceiver
いますが、別の場所からコンテキストを渡そうとしました。から LocationManager にアクセスすることはできませんBroadcastReceiver
か?