Android - Check if Location is Enabled

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

public boolean checkLocation() {
    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    boolean gps_enabled = false;

    try {
        gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch(Exception ex) {}

    if(gps_enabled) {
        return true;
    } else {
        return false;
    }
}

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API