androidlocationswitchinglocation-provider

Does specifying criteria switch the location provider in Android?


I want that the application should switch between GPS_PROVIDER and NETWORK_PROVIDER automatically. At present, I specify the providers in the program, so, if I specify criteria and set the locationlistener with that, then will it switch automatically to GPS_PROVIDER automatically whenever available?

For example, when the app started and listener was set at that time GPS_PROVIDER was not available or was not receiving location updates, but after some time it started receiving location updates then will the app automatically get the data from GPS_PROVIDER?

Otherwise, what is the best way of switching between the providers?

Just to add one more thing, the application will call requestLocationUpdates() only once in the app.


Solution

  • you can modify your onLocationChanged method like,

       @Override
    public void onLocationChanged(Location location) {
    
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){   
        Log.e("OnLocationChange Latitude",""+location.getLatitude());
                Log.e("OnLocationChange Longitude",""+location.getLongitude());
    
    }
    }
    

    now these lat,long are given by gps provider. and for your other question I think you tested the application on emulator.