Skip to content Skip to sidebar Skip to footer

How To Switch Provider Into Gps_provider If Android Phone Doesn't Have Internet Connection?

i make a location application on android. here's the code for acquiring lat and long value. public void geoLocation() { locationManager =(LocationManager)getSystemServi

Solution 1:

onLocationUpdate() just check for Internet is available or not,

If Internet is not available then just,

   locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

so like this,

ConnectivityManagercm= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfonetInfo= cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
} else {
    returnfalse;
}

EDIT: Here you can find beautiful explanation about Hoe to get current location,

What is the simplest and most robust way to get the user's current location in Android?

please refer this also.

Thanks

Post a Comment for "How To Switch Provider Into Gps_provider If Android Phone Doesn't Have Internet Connection?"