To retrieve the location from a NETWORK_PROVIDER you can use the following:
LocationListener locationListenerNetwork = new LocationListener() {
public void onLocationChanged(Location location) {
timer1.cancel();
locationResult.gotLocation(location);
lm.removeUpdates(this);
lm.removeUpdates(locationListenerGps);
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
LocationManager lm;
if(lm==null)
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
This is however a basic example, so to distinguish between the wi-fi and the 3g network first take a look here and before the code above do:
One certain way of obtaining what you want is the following:
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
State mobile = conMan.getNetworkInfo(0).getState();
State wifi = conMan.getNetworkInfo(1).getState();
After that, you distinguish them by:
if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
//mobile
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
//wifi
}
Check, if the mobile or wifi is connected, if wifi - then use PASSIVE_PROVIDER
, if mobile - use NETWORK_PROVIDER
.
I hope all of this information is useful for you.