device Location Opened - Android Map

Android examples for Map:Location

Description

device Location Opened

Demo Code


//package com.java2s;

import android.content.Context;

import android.location.LocationManager;

import android.provider.Settings;
import android.util.Log;

public class Main {

    public static boolean deviceLocationOpened(Context context) {
        return isGpsEnabled(context) || isNetworkEnabled(context);
    }//from   w w w  . j  a  v a  2  s .c om

    /**
     * @return true if GPS location is opened,or false
     */
    public static boolean isGpsEnabled(Context context) {
        String str1 = Settings.Secure.getString(
                context.getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        Log.v("GPS", str1);
        if (str1 != null) {
            return str1.contains(LocationManager.GPS_PROVIDER);
        } else {
            return false;
        }
    }

    /**
     * @return true if network location is opened,or false
     */
    public static boolean isNetworkEnabled(Context context) {
        String str1 = Settings.Secure.getString(
                context.getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        Log.v("GPS", str1);
        if (str1 != null) {
            return str1.contains(LocationManager.NETWORK_PROVIDER);
        } else {
            return false;
        }
    }
}

Related Tutorials