location manager issue for ice cream sandwhich

后端 未结 1 1728
醉酒成梦
醉酒成梦 2021-02-06 00:09

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

相关标签:
1条回答
  • 2021-02-06 00:24

    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.

    0 讨论(0)
提交回复
热议问题