List of usage examples for android.location LocationManager isProviderEnabled
public boolean isProviderEnabled(String provider)
From source file:com.tml.sharethem.receiver.ReceiverActivity.java
private boolean checkLocationAccess() { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Log.e(TAG, "GPS not enabled.."); buildAlertMessageNoGps();// w ww. j av a 2 s . co m return false; } return true; }
From source file:au.org.ala.fielddata.mobile.MobileFieldDataDashboard.java
@Override public void onStart() { super.onStart(); if (isLoggedIn()) { if (!preferences.getAskedAboutWifi()) { showWifiPreferenceDialog();/*from w w w. j ava2 s . c o m*/ } if (!askedAboutGPS) { if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { showNoGpsDialog(); } } } } }
From source file:com.esri.cordova.geolocation.AdvancedGeolocation.java
private void validatePermissions() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Reference: Permission Groups https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous // As of July 2016 - ACCESS_WIFI_STATE and ACCESS_NETWORK_STATE are not considered dangerous permissions Log.d(TAG, "validatePermissions()"); final int showRationale = _permissionsController.getShowRationale(); if (_permissionsController.getAppPermissions()) { startLocation();/*from www. j a v a2s.co m*/ } // The user has said to never ask again about activating location services else if (showRationale == _permissionsController.DENIED_NOASK) { Log.w(TAG, ErrorMessages.LOCATION_SERVICES_DENIED_NOASK().message); sendCallback(PluginResult.Status.ERROR, JSONHelper.errorJSON(PROVIDER_PRIMARY, ErrorMessages.LOCATION_SERVICES_DENIED_NOASK())); } else if (showRationale == _permissionsController.ALLOW) { requestPermissions(); } else if (showRationale == _permissionsController.DENIED) { Log.w(TAG, "Rationale already shown, geolocation denied twice"); sendCallback(PluginResult.Status.ERROR, JSONHelper.errorJSON(PROVIDER_PRIMARY, ErrorMessages.LOCATION_SERVICES_DENIED())); } } else { final LocationManager _locationManager = (LocationManager) _cordovaActivity .getSystemService(Context.LOCATION_SERVICE); final boolean networkLocationEnabled = _locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); final boolean gpsEnabled = _locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); final boolean networkEnabled = isInternetConnected(_cordovaActivity.getApplicationContext()); // If warnings are disabled then skip initializing alert dialog fragments if (!_noWarn && (!networkLocationEnabled || !gpsEnabled || !networkEnabled)) { alertDialog(gpsEnabled, networkLocationEnabled, networkEnabled); } else { startLocation(); } } }
From source file:edu.pdx.cecs.orcycle.MyApplication.java
private boolean isProviderEnabled() { final LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); return manager.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:in.codehex.arrow.MainActivity.java
/** * @param context context of the MainActivity class * @return true if GPS is enabled else false *///from w ww . j av a2s. c o m private boolean isGPSEnabled(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:es.uja.photofirma.android.CameraActivity.java
/** * Controla los accesos y retornos a las aplicaciones de caputura de fotografas y '@firma', se establece * para cada caso tanto la situacion de exito como la de fracaso. */// ww w. j a v a2 s . c o m @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Vuelta de @firma, el resultCode indica exito o fracaso, en cada caso se toman unas medidas diferentes if (requestCode == CameraActivity.APP_FIRMA_REQUEST_CODE && resultCode == CameraActivity.RESULT_ERROR) { logger.appendLog(402, "el usuario deniega el uso del certificado"); showErrorHeader(); } //Vuelta de @firma, la firma fue realizada con exito, se almacena la ruta al archivo if (requestCode == CameraActivity.APP_FIRMA_REQUEST_CODE && resultCode == RESULT_OK) { logger.appendLog(200, "@firma realiz la firma adecuadamente"); signedFileLocation = data.getExtras().getString("signedfilelocation"); showSuccessHeader(); } //Si la captura de la fotografa tuvo exito if (requestCode == CameraActivity.REQUEST_IMAGE_CAPTURE & resultCode == RESULT_OK) { logger.appendLog(101, "el usuario captura foto"); //Se obtienen los datos del servicio de localizacin geografica LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); // Aade los geoTags a la foto realizada anteriormente if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && location != null) { PhotoCapture.addExifData(photoLocation, location); logger.appendLog(102, "el usuario aade exif"); logger.appendLog(103, "gps data: " + location); } logger.appendLog(104, "buscando @firma"); //Se comprueba si est la app @firma Intent intent = getPackageManager().getLaunchIntentForPackage("es.gob.afirma"); if (intent == null) { //Si no se encuentra instalada se notifica al usuario logger.appendLog(400, "@firma no instalada"); showErrorHeader(); errorText.setText(getString(R.string.camera_activity_no_afirma_present)); } else { //Si se encuentra, entonces se abre para dar comienzo al proceso de firma logger.appendLog(201, "abriendo @firma"); Intent i = new Intent(APP_FIRMA_OPEN_ACTION); i.putExtra(CameraActivity.APP_FIRMA_EXTRA_FILE_PATH, photoLocation); startActivityForResult(i, APP_FIRMA_REQUEST_CODE); } } //Si la captura de fotos fue cancelada if (requestCode == CameraActivity.REQUEST_IMAGE_CAPTURE && resultCode == CameraActivity.RESULT_CANCELED) { showInfoHeader(); logger.appendLog(105, "cierra la app de photo sin captura"); } //Si la captura de fotos fue cancelada if (requestCode == CameraActivity.REQUEST_IMAGE_CAPTURE && resultCode == CameraActivity.RESULT_ERROR) { showInfoHeader(); logger.appendLog(403, "Se produjo un error en la app de Cmara"); } }
From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java
@Override public boolean onMyLocationButtonClick() { LocationManager mLocationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { ProgressManger.showToast(" ."); } else {/*from w w w . jav a 2 s. c om*/ ProgressManger.showToast(" ..."); } return false; }
From source file:com.zainsoft.ramzantimetable.QiblaActivity.java
private void checkForGPSnShowQibla() { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps();//from w ww . ja v a 2s .c o m Log.d(TAG, "GPS is OFF"); } else { Log.d(TAG, "GPS is ON"); registerForGPS(); onGPSOn(); } }
From source file:cc.softwarefactory.lokki.android.fragments.MapViewFragment.java
private void checkLocationServiceStatus() { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean gps = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean network = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!gps && !network && !MainApplication.locationDisabledPromptShown) { promptLocationService();/*from w ww . ja v a2 s .c om*/ MainApplication.locationDisabledPromptShown = true; } }
From source file:com.mobantica.DriverItRide.activities.ActivityLogin.java
private boolean valid() { if (edt_login_username.getText().toString().equals("")) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enter_username), Toast.LENGTH_SHORT).show(); return false; }//from ww w.j av a2 s . c o m if (edt_login_password.getText().toString().equals("")) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enter_password), Toast.LENGTH_SHORT).show(); return false; } if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, getResources().getString(R.string.need_location_permission_in_app_setting), Toast.LENGTH_SHORT).show(); return false; } if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, getResources().getString(R.string.need_phone_permission_in_app_setting), Toast.LENGTH_SHORT).show(); return false; } if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, getResources().getString(R.string.need_write_external_storage_permissionin_app_setting), Toast.LENGTH_SHORT).show(); return false; } LocationManager locationManager = (LocationManager) getApplicationContext() .getSystemService(Context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enable_location), Toast.LENGTH_SHORT).show(); return false; } return true; }