List of usage examples for android.content Context LOCATION_SERVICE
String LOCATION_SERVICE
To view the source code for android.content Context LOCATION_SERVICE.
Click Source Link
From source file:com.patil.geobells.lite.MainActivity.java
public void checkLocationServicesEnabled() { LocationManager lm = null;//ww w . j a v a 2 s . c om boolean gps_enabled = true, network_enabled = true; if (lm == null) lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); try { gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { } try { network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ex) { } if (!gps_enabled || !network_enabled) { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.dialog_title_enable_locationservices); dialog.setMessage(getString(R.string.dialog_message_enable_locationservices)); dialog.setCancelable(false); dialog.setPositiveButton(getString(R.string.dialog_button_open_location_settings), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface, int paramInt) { paramDialogInterface.dismiss(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(myIntent); } }); dialog.setNegativeButton(getString(R.string.dialog_button_nothanks), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface, int paramInt) { finish(); } }); dialog.create().show(); } }
From source file:com.platform.middlewares.plugins.GeoLocationPlugin.java
private JSONObject getAuthorizationError(Context app) { String error = null;/*from w w w .j av a2 s .c o m*/ LocationManager lm = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE); boolean gps_enabled = false; boolean network_enabled = false; try { gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ignored) { } try { network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ignored) { } if (!gps_enabled && !network_enabled) { error = "Location services are disabled"; } int permissionCheck = ContextCompat.checkSelfPermission(app, Manifest.permission.ACCESS_FINE_LOCATION); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { error = "Location services are not authorized"; } if (error != null) { JSONObject obj = new JSONObject(); try { obj.put("error", error); } catch (JSONException e) { e.printStackTrace(); } return obj; } else { return null; } }
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. *///w ww.ja v a2s. 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:digital.dispatch.TaxiLimoNewUI.GCM.GCMIntentService.java
private Location getLocationByProvider(String provider) { Location location = null;/*from ww w .j av a 2s. com*/ LocationManager locationManager = (LocationManager) c.getSystemService(Context.LOCATION_SERVICE); try { if (locationManager.isProviderEnabled(provider)) { location = locationManager.getLastKnownLocation(provider); } } catch (IllegalArgumentException e) { Logger.d(TAG, "Cannot acces Provider " + provider); } return location; }
From source file:com.androzic.location.LocationService.java
private void connect() { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager != null) { lastLocationMillis = 0;//from w w w .j a v a 2 s .c o m pause = 1; isContinous = false; justStarted = true; smoothSpeed = 0.0f; avgSpeed = 0.0f; locationManager.addGpsStatusListener(this); if (useNetwork) { try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); Log.d(TAG, "Network provider set"); } catch (IllegalArgumentException e) { Toast.makeText(this, getString(R.string.err_no_network_provider), Toast.LENGTH_LONG).show(); } } try { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); locationManager.addNmeaListener(this); Log.d(TAG, "Gps provider set"); } catch (IllegalArgumentException e) { Log.d(TAG, "Cannot set gps provider, likely no gps on device"); } startForeground(NOTIFICATION_ID, getNotification()); } }
From source file:com.code19.library.SystemUtils.java
/** * <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> *//*from w w w. jav a2 s. co m*/ public static boolean isGpsEnabled(Context context) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return lm.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:com.magicmod.mmweather.MainActivity.java
private void updateByGeoLocation() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); Log.d(TAG, "Current location is " + location); boolean needsUpdate = location == null; if (location == null) { Toast.makeText(mContext, mContext.getString(R.string.geo_location_fail_info), Toast.LENGTH_LONG).show(); }/*from w ww .java 2 s. c o m*/ if (location != null) { long delta = System.currentTimeMillis() - location.getTime(); needsUpdate = delta > Constants.OUTDATED_LOCATION_THRESHOLD_MILLIS; } if (needsUpdate) { // TODO: use a better way to get location } if (location != null) { new WeatherUpdateTask(location, Preferences.isMetric(mContext)).execute(); } }
From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java
public void getCurrentLocation(double latitude, double longitude) { googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.maparrive)).getMap(); googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.setMyLocationEnabled(true); LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Location l = null;/*from w w w . java 2 s . c om*/ if (googleMap != null) { googleMap.clear(); MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title(""); marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(latitude, longitude)) .zoom(10).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); googleMap.addMarker(marker); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { } googleMap.setMyLocationEnabled(true); } if (latitude != 0.0d && longitude != 0.0d) { Intent intent = new Intent(getActivity(), BackgroundService.class); intent.putExtra("userid", mUserId); intent.putExtra("lat", String.valueOf(latitude)); intent.putExtra("long", String.valueOf(longitude)); getActivity().startService(intent); } }
From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java
private void initializeBackend() { // parse input xml data res = getResources();//from ww w .ja v a 2 s. com density = res.getDisplayMetrics().density; showProgress = AnimationUtils.loadAnimation(FanWallPlugin.this, R.anim.show_progress_anim); hideProgress = AnimationUtils.loadAnimation(FanWallPlugin.this, R.anim.hide_progress_anim); currentIntent = getIntent(); widget = (Widget) currentIntent.getSerializableExtra("Widget"); String tempCachePath = widget.getCachePath(); EntityParser parser = new EntityParser(); try { if (TextUtils.isEmpty(widget.getPluginXmlData())) { if (TextUtils.isEmpty(currentIntent.getStringExtra("WidgetFile"))) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000); return; } } if (!TextUtils.isEmpty(widget.getPluginXmlData())) { parser.parse(widget.getPluginXmlData()); } else { String xmlData = readXmlFromFile(currentIntent.getStringExtra("WidgetFile")); parser.parse(xmlData); } } catch (Exception e) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000); return; } Statics.hasAd = widget.isHaveAdvertisement(); Statics.appName = widget.getAppName(); Statics.near = parser.getNear(); Statics.MODULE_ID = parser.getModuleId(); Statics.canEdit = parser.getCanEdit(); Statics.APP_ID = parser.getAppId(); Statics.color1 = parser.getColor1(); Statics.color2 = parser.getColor2(); Statics.color3 = parser.getColor3(); Statics.color4 = parser.getColor4(); Statics.color5 = parser.getColor5(); if (Statics.BackColorToFontColor(Statics.color1) == Color.WHITE) Statics.isSchemaDark = true; else Statics.isSchemaDark = false; // init cache path if (!TextUtils.isEmpty(tempCachePath)) Statics.cachePath = tempCachePath + "/fanwall-" + widget.getOrder(); Statics.onAuthListeners.add(this); // register separate LocationManager.GPS_PROVIDER for register status change events locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Statics.currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, new LocationListener() { @Override public void onLocationChanged(Location location) { Statics.currentLocation = location; } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, true); enableGpsCheckbox.setChecked(true); } @Override public void onProviderDisabled(String s) { Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, false); enableGpsCheckbox.setChecked(false); } }); }
From source file:com.towson.wavyleaf.Sighting.java
protected void refresh() { // Check for GPS LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); playAPKEnabled = doesDeviceHaveGooglePlayServices(); currentEditableLocation = locationData.getLocation(); if (!isAccurateLocation(currentEditableLocation)) { // If location isn't accurate if (!gpsEnabled) { // If GPS is disabled buildAlertMessageNoGps();//from w ww. ja v a 2 s . c om } else if (gpsEnabled) { if (playAPKEnabled) { setUpMapIfNeeded(); wheresWaldo(); } } updateLocationTimer = new Timer(); TimerTask updateLocationTask = new TimerTask() { @Override public void run() { checkLocation(); } }; updateLocationTimer.scheduleAtFixedRate(updateLocationTask, 0, FIVE_SECONDS); } else setUpMapIfNeeded(); }