Example usage for android.location LocationManager isProviderEnabled

List of usage examples for android.location LocationManager isProviderEnabled

Introduction

In this page you can find the example usage for android.location LocationManager isProviderEnabled.

Prototype

public boolean isProviderEnabled(String provider) 

Source Link

Document

Returns the current enabled/disabled status of the given provider.

Usage

From source file:com.forrestguice.suntimeswidget.getfix.GetFixHelper.java

public static boolean isNetProviderEnabled(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}

From source file:com.forrestguice.suntimeswidget.getfix.GetFixHelper.java

public static boolean isPassiveProviderEnabled(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER);
}

From source file:com.luke.lukef.lukeapp.tools.LukeUtils.java

/**
 * Checks the current GPS status, if GPS is not enabled then calls
 * {@link LukeUtils#alertDialogBuilder(Context, String, String)} to create a prompt for the user
 * to enable GPS./*  w ww . j  a v  a  2 s.  c o m*/
 *
 * @param context Context, needed to create the alert.
 * @return <b>true</b> if the GPS is enabled, <b>false</b> if it's not.
 */
public static boolean checkGpsStatus(Context context) {
    final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        alertDialogBuilder(context, noGps, android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        return false;
    } else {
        return true;
    }
}

From source file:it.feio.android.omninotes.utils.GeocodeHelper.java

public static LocationManager getLocationManager(Context context, final LocationListener locationListener) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    // A check is done to avoid crash when NETWORK_PROVIDER is not
    // available (ex. on emulator with API >= 11)
    if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)
            && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 50, locationListener);
    }/*www .  j  a v a 2s. com*/
    if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)
            && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 50, locationListener);
    } else {
        locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 60000, 50, locationListener);
    }
    return locationManager;
}

From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java

public static boolean locationProviderEnabled(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    for (int pi = 0; pi < PROVIDERS.length; pi++) {
        String provider = PROVIDERS[pi];
        if (!locationManager.isProviderEnabled(provider))
            return false;
    }/*from w  w w .  jav  a2  s.  c o m*/
    return true;
}

From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java

public static String getLocationProviderError(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    for (int pi = 0; pi < PROVIDERS.length; pi++) {
        String provider = PROVIDERS[pi];
        if (!locationManager.isProviderEnabled(provider))
            return "Please enable location provider \"" + provider + "\"";
    }//  ww  w.j  ava  2  s. c o  m
    return null;
}

From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java

public static Location getCurrentLocation(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    for (int pi = 0; pi < PROVIDERS.length; pi++) {
        String provider = PROVIDERS[pi];
        if (!locationManager.isProviderEnabled(provider)) {
            Log.e(TAG, "Required location provider " + provider + " disabled (getCurrentLocation)");
        } else {//from w  w w  .jav  a  2 s .c  o m
            Location loc = locationManager.getLastKnownLocation(provider);
            if (loc != null) {
                long age = System.currentTimeMillis() - loc.getTime();
                if (age > MAX_CURRENT_LOCATION_AGE_MS) {
                    Log.w(TAG, "Location provider " + provider + " last location is too old (" + age + " ms)");
                } else {
                    // TODO accuracy requirement?
                    return loc;
                }
            }
        }
    }
    return null;
}

From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java

public static boolean isLocalisationEnabled(Context context, ProviderEnum provider) {
    boolean result = false;
    switch (provider) {
    case GPS_PROVIDER:
    case GSM_PROVIDER: {
        LocationManager locationManager = getLocationManager(context);
        if (locationManager != null) {
            try {
                result = locationManager.isProviderEnabled(provider.getAndroidProvider());
            } catch (Exception e) {
                result = false;/* ww w.  ja v  a2s .c  o m*/
            }
        }
        break;
    }
    case XPS_PROVIDER: {
        LocationManager locationManager = getLocationManager(context);
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if ((locationManager != null) && (wm != null)) {
            try {
                result = (locationManager.isProviderEnabled(ProviderEnum.GPS_PROVIDER.getAndroidProvider()) //
                        || locationManager.isProviderEnabled(ProviderEnum.GSM_PROVIDER.getAndroidProvider())) //
                        && wm.isWifiEnabled();
            } catch (Exception e) {
                result = false;
            }
        }
        break;
    }
    case WIFI_PROVIDER: {
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wm != null) {
            result = wm.isWifiEnabled();
        }
        break;
    }
    case IP_PROVIDER: {
        result = true;
        break;
    }
    default:
        break;
    }
    return result;
}

From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java

public static void registerOnThread(Context context, LocationListener locationCallback, Listener listener) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = locationManager.getAllProviders();
    Log.i(TAG, "Found " + providers.size() + " location providers");
    for (String provider : providers) {
        if (locationManager.isProviderEnabled(provider)) {
            Log.i(TAG, "Provider " + provider + " enabled");
        } else {//from   www .  ja v  a 2s  . c  o  m
            Log.i(TAG, "Provider " + provider + " disabled");
        }
    }
    for (int pi = 0; pi < PROVIDERS.length; pi++) {
        String provider = PROVIDERS[pi];
        if (locationManager.isProviderEnabled(provider)) {
            Log.i(TAG, "Registering with provider " + provider);
            Location loc = locationManager.getLastKnownLocation(provider);
            if (loc != null) {
                Log.i(TAG,
                        "Last Location, provider=" + loc.getProvider() + ", lat=" + loc.getLatitude()
                                + ", long=" + loc.getLongitude() + ", bearing="
                                + (loc.hasBearing() ? "" + loc.getBearing() : "NA") + ", speed="
                                + (loc.hasSpeed() ? "" + loc.getSpeed() : "NA") + ", accuracy="
                                + (loc.hasAccuracy() ? "" + loc.getAccuracy() : "NA") + ", alt="
                                + (loc.hasAltitude() ? "" + loc.getAltitude() : "NA"));

                ZoneService.updateLocation(context, loc);

            }
            //if (!"passive".equals(provider))
            if (locationCallback != null)
                locationManager.requestLocationUpdates(provider, 0/*minTime*/, 0/*minDistance*/,
                        locationCallback);
        } else
            Log.e(TAG, "Required provider " + provider + " not enabled!");
    }
    if (listener != null)
        locationManager.addGpsStatusListener(listener);
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 *  GPS?//from   w  ww  .  j  a  v  a2s.c  om
 * <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 */
public static boolean isGpsEnabled(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    // GPS????24????
    boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    // WLAN(3G/2G)?AGPSGPS????
    boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    return gps || network;
}