Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.content.Context;

import android.location.LocationManager;

public class Main {
    /** A reference to the system Location Manager. */
    private static LocationManager mLocationManager;

    /** Returns true if GPS provider is enabled, otherwise false. */
    public static final boolean isGpsEnabled() {
        loadLocationManager();
        try {
            return mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        } catch (Exception e) {
            return false;
        }
    }

    /** Instantiates the mLocationManager variable if needed. */
    private static final void loadLocationManager() {
        if (mLocationManager == null) {
            mLocationManager = (LocationManager) (new Activity().getApplicationContext())
                    .getSystemService(Context.LOCATION_SERVICE);
        }
    }
}