Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

location manager issue for ice cream sandwhich

Tags:

android

gps

can anybody explain me what is this error ? I am getting only for android 4 + and not for below:

E/AndroidRuntime(891): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.getaddress/com.example.getaddress.MainActivity}: java.lang.IllegalArgumentException: requested provider network doesn't exisit

like image 227
Aditya Unhale Avatar asked Jul 09 '12 12:07

Aditya Unhale


1 Answers

It appears that the NETWORK_PROVIDER location provider is not accessible in Android 4+ emulators without Google APIs (well actually I have not tested on all of them ,see below). The real devices I have tested on are OK with it (but they all have Google services on them, it would be interesting to test with custom, clean Android versions, maybe with Kindles?).

It is not a question on enabling/disabling the provider in the device settings, it is simply not there in the emulator.

Symptom

Basically this code:

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,mLocListener);

will cause the following exception:

java.lang.IllegalArgumentException: provider doesn't exisit: null

on all Android 4+ naked emulators (as opposed to Google-bound emulators)

note: the typo in "exisit" is in the actual log line.

Diagnostic

Getting a list of all location providers on the target device with the following:

List<String> providers = locationManager.getAllProviders();

I can see that the network provider is present on

  • physical devices
  • android 2.3.3 emulator (no Google APIs)
  • android level 17 (4.2) emulator (with Google APIs)

But not on

  • android level 15 (4.0.3) emulator with Google APIs
  • android 4.2 emulator (no Google APIs)

My guess is that for non-technical reasons, Google has not allowed the network location service in AOSP and limited its usage to the Google-bound versions of the OS from 4.2 (?).

What I don't know if whether or not there is a replacement network location service on non-Google devices (such as Kindle).

Probable impact on your app

I would not expect this to have any impact on most smartphones and tablets. However it can

  • somewhat impair your ability to test
  • be a compatibility issue for users that use custom/non-Google versions of Android (once again, Kindle?)

How to detect

A simple test such as:

locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)

can tell you painlessly if the network provider is present on the device. Note that if it is present, but the user has not activated it, your LocationListener will receive an onProviderDisabled callback following the location request.

like image 113
Stéphane Avatar answered Oct 07 '22 08:10

Stéphane