OK so basically I want to start listening for a single update from a BroadcastReceiver
, and for some reason all the providers are disabled from my access. Here is the code snippet
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));
}
and my logcat results
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...
I am guessing that the issue is that I am calling all of this from a BroadcastReceiver
, but I tried passing it context from somewhere else. Is it not possible to access LocationManager from a BroadcastReceiver
?
Wow I feel like such an idiot. Well guys it was simply a permission issue. If anyone runs across this again then just add the use permissions to manifest
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />