is Able To Get Location - Android Map

Android examples for Map:Location

Description

is Able To Get Location

Demo Code


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

public class Main {
    public static boolean isAbleToGetLocation(Context context) {
        if (!isOnline(context) && !isGPSEnable(context)) {
            return false;
        }//w ww. ja  va2  s.  c o m
        return true;
    }

    public static boolean isOnline(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }
        return false;
    }

    private static boolean isGPSEnable(Context context) {
        final LocationManager manager = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            return true;
        }
        return false;
    }
}

Related Tutorials