Here you can find the source of getLocationProvider(Context context)
public static LocationProvider getLocationProvider(Context context)
//package com.java2s; import android.content.Context; import android.location.LocationManager; import android.location.LocationProvider; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static LocationProvider getLocationProvider(Context context) { if (context != null) { LocationProvider networkProvider = null; LocationProvider gpsProvider = null; // Get location manager LocationManager lm = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); // Get network and GPS provider if available if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { networkProvider = lm/* w ww. j av a 2s . c om*/ .getProvider(LocationManager.NETWORK_PROVIDER); } if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { gpsProvider = lm.getProvider(LocationManager.GPS_PROVIDER); } if (networkProvider != null && isNetworkConnected(context)) { // Use network provider if it's available and network is // connected return networkProvider; } else if (gpsProvider != null) { // Otherwise use GPS provider return gpsProvider; } else { // But never use passive provider as it's too slow return null; } } else { return null; } } public static boolean isNetworkConnected(Context context) { if (context != null) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); } else { return false; } } }