location manager issue for ice cream sandwhich

我们两清 提交于 2019-12-20 14:15:57

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/11394825/location-manager-issue-for-ice-cream-sandwhich

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!