List of usage examples for android.location LocationManager getProviders
public List<String> getProviders(boolean enabledOnly)
From source file:Main.java
public static boolean isGPSEnabled(Context context) { LocationManager lm = ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE)); List<String> accessibleProviders = lm.getProviders(true); return accessibleProviders != null && accessibleProviders.size() > 0; }
From source file:Main.java
public static boolean isGpsEnabled(Context context) { LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> accessibleProviders = manager.getProviders(true); return accessibleProviders != null && accessibleProviders.size() > 0; }
From source file:Main.java
public static boolean isGPSEnabled(Context cxt) { LocationManager locationManager = ((LocationManager) cxt.getSystemService(Context.LOCATION_SERVICE)); List<String> accessibleProviders = locationManager.getProviders(true); return accessibleProviders != null && accessibleProviders.size() > 0; }
From source file:Main.java
public static Location getLastKnownLocation(Context context) { LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = manager.getProviders(true); for (String provider : providers) { Location location = manager.getLastKnownLocation(provider); if (location != null) { return location; }// www . ja va 2 s . c o m } // At this point we've done all we can and no location is returned return null; }
From source file:Main.java
public static boolean isGpsEnabled(Context context) { LocationManager locationManager = ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE)); List<String> accessibleProviders = locationManager.getProviders(true); return accessibleProviders != null && accessibleProviders.size() > 0; }
From source file:Main.java
/** * Returns current (last known) location of the system. If the context is missing permissions * (ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION) or location tracking is disabled by user, this * will fail and return null./*from w w w .j ava 2 s .c o m*/ * * @param context * Application context of caller * @return Current location or null if we could not retrieve current location */ public static Location getCurrentLocation(Context context) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); // Find most accurate last known location Location location = null; for (int i = providers.size() - 1; i >= 0; i--) { location = lm.getLastKnownLocation(providers.get(i)); if (location != null) break; } return location; }
From source file:org.navitproject.navit.NavitDownloadSelectMapActivity.java
private void updateMapsForLocation(NavitMapDownloader.osm_map_values[] osm_maps) { Location currentLocation = NavitVehicle.lastLocation; if (maps_current_position_childs.size() == 0 || (currentLocation != null && !currentLocationKnown)) { if (currentLocation == null) { LocationManager mapLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = mapLocationManager.getProviders(true); long lastUpdate; long bestUpdateTime = -1; for (String provider : providers) { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; }// w w w . j a va 2 s.co m Location lastKnownLocation = mapLocationManager.getLastKnownLocation(provider); if (lastKnownLocation != null) { lastUpdate = lastKnownLocation.getTime(); if (lastUpdate > bestUpdateTime) { currentLocation = lastKnownLocation; bestUpdateTime = lastUpdate; } } } } else { currentLocationKnown = true; } if (currentLocation != null) { // if this map contains data to our current position, add it to // the MapsOfCurrentLocation-list for (int currentMapIndex = 0; currentMapIndex < osm_maps.length; currentMapIndex++) { if (osm_maps[currentMapIndex].isInMap(currentLocation)) { HashMap<String, String> currentPositionMapChild = new HashMap<String, String>(); currentPositionMapChild.put("map_name", osm_maps[currentMapIndex].map_name + " " + (osm_maps[currentMapIndex].est_size_bytes / 1024 / 1024) + "MB"); currentPositionMapChild.put("map_index", String.valueOf(currentMapIndex)); maps_current_position_childs.add(currentPositionMapChild); } } } } }
From source file:com.metinkale.prayerapp.compass.Main.java
@Override protected void onResume() { super.onResume(); mSensorManager.unregisterListener(mMagAccel); mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME); if (mSelCity == null) { mSelCity = (TextView) findViewById(R.id.selcity); mSelCity.setOnClickListener(new OnClickListener() { @Override//from w w w . j a v a 2 s . co m public void onClick(View arg0) { if (App.isOnline()) { startActivity(new Intent(Main.this, LocationPicker.class)); } else { Toast.makeText(Main.this, R.string.noConnection, Toast.LENGTH_LONG).show(); } } }); } if (PermissionUtils.get(this).pLocation) { LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = locMan.getProviders(true); for (String provider : providers) { locMan.requestLocationUpdates(provider, 0, 0, this); Location lastKnownLocation = locMan.getLastKnownLocation(provider); if (lastKnownLocation != null) { calcQiblaAngel(lastKnownLocation); } } } if (Prefs.getCompassLat() != 0) { Location loc = new Location("custom"); loc.setLatitude(Prefs.getCompassLat()); loc.setLongitude(Prefs.getCompassLng()); calcQiblaAngel(loc); } }
From source file:com.metinkale.prayerapp.vakit.AddCity.java
@SuppressWarnings("MissingPermission") public void checkLocation() { if (PermissionUtils.get(this).pLocation) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location loc = null;// w w w.j av a 2 s . co m List<String> providers = lm.getProviders(true); for (String provider : providers) { Location last = lm.getLastKnownLocation(provider); // one hour==1meter in accuracy if ((last != null) && ((loc == null) || ((last.getAccuracy() - (last.getTime() / (1000 * 60 * 60))) < (loc.getAccuracy() - (loc.getTime() / (1000 * 60 * 60)))))) { loc = last; } } if (loc != null) onLocationChanged(loc); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_MEDIUM); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false); criteria.setSpeedRequired(false); String provider = lm.getBestProvider(criteria, true); if (provider != null) { lm.requestSingleUpdate(provider, this, null); } } else { PermissionUtils.get(this).needLocation(this); } }
From source file:com.metinkale.prayerapp.compass.Main.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mRefresh == item) { mOnlyNew = true;/* w ww. java2 s .c o m*/ if (PermissionUtils.get(this).pLocation) { LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locMan.removeUpdates(this); List<String> providers = locMan.getProviders(true); for (String provider : providers) { locMan.requestLocationUpdates(provider, 0, 0, this); } } } else if (mSwitch == item) { if (mMode == Mode.Map) { mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME); updateFrag(Mode.TwoDim); mSwitch.setIcon(MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.MAP) .setColor(Color.WHITE).setToActionbarSize().build()); } else if (PermissionUtils.get(this).pLocation) { mSensorManager.unregisterListener(mMagAccel); updateFrag(Mode.Map); mSwitch.setIcon(MaterialDrawableBuilder.with(this) .setIcon(MaterialDrawableBuilder.IconValue.COMPASS_OUTLINE).setColor(Color.WHITE) .setToActionbarSize().build()); } else { Toast.makeText(this, R.string.permissionNotGranted, Toast.LENGTH_LONG).show(); } } return super.onOptionsItemSelected(item); }