is Location Service Enabled - Android Map

Android examples for Map:Location

Description

is Location Service Enabled

Demo Code


//package com.java2s;
import android.content.Context;
import android.location.LocationManager;

public class Main {
    public static boolean isLocationServiceEnabled(Context context) {
        LocationManager locationManager = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        boolean gps_enabled = false;
        boolean network_enabled = false;
        try {/* ww  w  .j ava2 s .c  o m*/
            gps_enabled = locationManager
                    .isProviderEnabled(LocationManager.GPS_PROVIDER);
        } catch (Exception ex) {
            //we don't bother, we just want to know if it is enabled, exception means not enabled
        }
        try {
            network_enabled = locationManager
                    .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
            //we don't bother, we just want to know if it is enabled, exception means not enabled
        }
        return gps_enabled || network_enabled;
    }
}

Related Tutorials