Java tutorial
//package com.java2s; /* * Project: NextGIS mobile apps for Compulink * Purpose: Mobile GIS for Android * Authors: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru * NikitaFeodonit, nfeodonit@yandex.com * ***************************************************************************** * Copyright (C) 2014-2015 NextGIS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import android.content.Context; import android.location.LocationManager; import android.os.Build; import android.provider.Settings; import android.text.TextUtils; public class Main { public static boolean isOnlyGpsLocationModeEnabled(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int locationMode; try { locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (Settings.SettingNotFoundException e) { return false; } // GPS must be enabled return Settings.Secure.LOCATION_MODE_SENSORS_ONLY == locationMode || Settings.Secure.LOCATION_MODE_HIGH_ACCURACY == locationMode; } else { String locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (TextUtils.isEmpty(locationProviders)) { return false; } String[] providers = locationProviders.split(","); for (String provider : providers) { // GPS must be enabled if (provider.equals(LocationManager.GPS_PROVIDER)) { return true; } } return false; } } }