Example usage for android.content Context LOCATION_SERVICE

List of usage examples for android.content Context LOCATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context LOCATION_SERVICE.

Prototype

String LOCATION_SERVICE

To view the source code for android.content Context LOCATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates.

Usage

From source file:Main.java

public static String getLocation(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    String provider = LocationManager.NETWORK_PROVIDER;
    Location location = locationManager.getLastKnownLocation(provider);
    return location.getLatitude() + ":" + location.getLongitude();
}

From source file:Main.java

public static boolean isGPSAvailable(Context context) {
    LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
        return true;
    } else {//w w w  . j a v a2  s .c o m
        return false;
    }
}

From source file:Main.java

public static boolean isNetworkEnable(Context ctx) {

    LocationManager locationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}

From source file:Main.java

public static boolean isGpsOpened(Context context) {
    LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
        return true;
    } else {/*from  w w w. j a va  2  s.co  m*/
        return false;
    }
}

From source file:Main.java

public static boolean isGpsEnabled(Context pContext) {
    LocationManager locationManager = (LocationManager) pContext.getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:Main.java

public static boolean isGpsOn(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    if (gpsEnabled) {
        return true;
    } else {//from  w w w. java  2 s.  c o m
        return false;
    }
}

From source file:Main.java

public static void beginListening(Context ctx, LocationListener ll) {
    LocationManager lm = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
    if (lm.getProvider(LocationManager.GPS_PROVIDER) != null) {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
    } else if (lm.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll);
    } else {//from  www  .  j a  v  a2s .c o m
        lm.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, ll);
    }
}

From source file:Main.java

public static boolean isOpenGPS(Context context) {

    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean isGPSEnable = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    boolean isNPEnable = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    return isGPSEnable || isNPEnable;

}

From source file:Main.java

public static boolean isGpsEnabled(Context context) {
    LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    List<String> accessibleProviders = manager.getProviders(true);
    return accessibleProviders != null && accessibleProviders.size() > 0;
}

From source file:Main.java

public static boolean checkLocationService(Context context) {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean gps_enabled = false;
    boolean network_enabled = false;

    try {/* www.  jav a 2 s  . c o  m*/
        gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch (Exception ex) {
    }

    try {
        network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    } catch (Exception ex) {
    }

    return gps_enabled;
}