NETWORK_PROVIDER did not work in versions of Android 4.0 and higher / API level 14 and higher

In android 4.0 and above call

LocationManager.requestLocationUpdates (LocationManager.NETWORK_PROVIDER, 0, 0, listener)

gives an exception like

Called: java.lang.IllegalArgumentException: provider = network.

Even if the network is turned on, the same exception is thrown.

I know this is a registered issue (http://code.google.com/p/android/issues/detail?id=19857).

My question is.

How to get a location by a network provider or in any other way (and not GPS) in Android 4.0 and higher?

+5
source share
3 answers

android 4.0, , Android, , .

+1

, , .

, LocationManager, :

    LocationManager locationManager = (LocationManager)context.getSystemService( Context.LOCATION_SERVICE );

    Criteria criteria = new Criteria();
    criteria.setAccuracy( Criteria.ACCURACY_COARSE );
    String provider = locationManager.getBestProvider( criteria, true );

    if ( provider == null ) {
        Log.e( TAG, "No location provider found!" );
        return;
    }

    lastLocation = locationManager.getLastKnownLocation(provider);
0

Yes, this support is available with a newer version that you can check.

0
source

All Articles