@Test public void shouldReturnAllProviders() throws Exception { assertThat(locationManager.getAllProviders().size()).isEqualTo(3); shadowLocationManager.setProviderEnabled("MY_PROVIDER", false); assertThat(locationManager.getAllProviders().size()).isEqualTo(4); }
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(new Criteria(), true); Location locations = locationManager.getLastKnownLocation(provider); List<String> providerList = locationManager.getAllProviders(); if(null!=locations && null!=providerList && providerList.size()>0){ double longitude = locations.getLongitude(); double latitude = locations.getLatitude(); Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1); if(null!=listAddresses&&listAddresses.size()>0){ String _Location = listAddresses.get(0).getAddressLine(0); } } catch (IOException e) { e.printStackTrace(); } }
for (String s : locationManager.getAllProviders()) { locationManager.requestLocationUpdates(s, checkInterval, minDistance, new LocationListener() {
private void openGPSListener() { progressDialog.show(); try { if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } //Waiting gps max timeout is 20s diaryHandler.sendEmptyMessageDelayed(0, GPS_TIMEOUT); } catch (SecurityException e) { //do nothing } }
try { if (theFrag.diaryLocations != null) { List<String> providerList = theFrag.locationManager.getAllProviders(); if (null != theFrag.diaryLocations && null != providerList && providerList.size() > 0) { double longitude = theFrag.diaryLocations.getLongitude();
try { if (theFrag.diaryLocations != null) { List<String> providerList = theFrag.locationManager.getAllProviders(); if (null != theFrag.diaryLocations && null != providerList && providerList.size() > 0) { double longitude = theFrag.diaryLocations.getLongitude();
/** * Check if given provider exists on device * @param provider Provider * @return True if exists, false otherwise */ private boolean providerExists(String provider) { return locManager.getAllProviders().contains(provider); }
public static boolean hasNetworkLocationDevice(Context context) { final LocationManager mgr = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); if (mgr == null) { return false; } final List<String> providers = mgr.getAllProviders(); if (providers == null) { return false; } return providers.contains(LocationManager.NETWORK_PROVIDER); }
public static boolean hasGPSDevice(Context context) { final LocationManager mgr = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); if (mgr == null) { return false; } final List<String> providers = mgr.getAllProviders(); if (providers == null) { return false; } return providers.contains(LocationManager.GPS_PROVIDER); }
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = null; List providers = lm.getAllProviders(); for (Object 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; } Location loc = lm.getLastKnownLocation((String) provider); if (provider.equals(TEST_MOCK_GPS_LOCATION)) { mLastLocation = loc; } }
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Intent intent = new Intent(context, LocationReceiver.class); pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); List<String> knownProviders = locationManager.getAllProviders(); if(locationManager != null && pendingIntent != null && knownProviders.contains(LocationManager.GPS_PROVIDER)){ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINUTE_INTERVAL*5, 0, pendingIntent); } if(locationManager != null && pendingIntent != null && knownProviders.contains(LocationManager.NETWORK_PROVIDER)){ locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINUTE_INTERVAL*5, 0, pendingIntent); }
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = manager.getAllProviders(); Location loc; for (int i = 0; i < providers.size(); i++) { loc = manager.getLastKnownLocation(providers.get(i)); loc.getTime(); /* * put your code here * compare loc from providers to get the most * recent location */ } }
@Override public boolean exists(Context context) { return getLocationManager(context).getAllProviders().contains(getLocationProvider()); }
private boolean updateLocation() { if (!TextUtils.isEmpty(provider) && locationManager.getAllProviders().contains(provider)) { Location l = locationManager.getLastKnownLocation(provider); if (l != null) { location = l; } Result result = buildResult(); if (result != null) { dispatchResult(result); return true; } } return false; }
public void switchOn() { if (!LocationFinderState.Active.equals(state)) { mLocationManager = mixContext.GetLocationManager(); locationResolvers.clear(); for (String p : mLocationManager.getAllProviders()) { if(mLocationManager.isProviderEnabled(p)) { LocationResolver lr = new LocationResolver(mLocationManager, p, this); locationResolvers.add(lr); } } state = LocationFinderState.Confused; } }
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(new Criteria(), true); Location locations = locationManager.getLastKnownLocation(provider); List<String> providerList = locationManager.getAllProviders(); if(null!=locations && null!=providerList && providerList.size()>0){ double longitude = locations.getLongitude(); double latitude = locations.getLatitude(); Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1); if(null!=listAddresses&&listAddresses.size()>0){ String _Location = listAddresses.get(0).getAddressLine(1); } } catch (IOException e) { e.printStackTrace(); }
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(new Criteria(), true); Location locations = locationManager.getLastKnownLocation(provider); List<String> providerList = locationManager.getAllProviders(); if(null!=locations && null!=providerList && providerList.size()>0){ double longitude = locations.getLongitude(); double latitude = locations.getLatitude(); Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1); if(null!=listAddresses&&listAddresses.size()>0){ String _Location = listAddresses.get(0).getAddressLine(0); } } catch (IOException e) { e.printStackTrace(); } }
private boolean gpsRequestLocation() { boolean isGPSEnabled = AppPreference.isGpsEnabledByPreferences(getBaseContext()) && locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (isGPSEnabled && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Looper locationLooper = Looper.myLooper(); appendLog(getBaseContext(), TAG, "get location from GPS"); timerHandlerGpsLocation.postDelayed(timerRunnableGpsLocation, GPS_LOCATION_TIMEOUT_IN_MS); locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, gpsLocationListener, locationLooper); startRefreshRotation("gpsRequestLocation", 3); return true; } else { return false; } }
LocationManager location_manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); LocationListener listner = new MyLocationListener(); boolean networkLocationEnabled = location_manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); boolean gpsLocationEnabled = location_manager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (networkLocationEnabled || gpsLocationEnabled) { if (location_manager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER) && networkLocationEnabled) { location_manager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 2000, 2000, listner); location_manager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } else if (location_manager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && gpsLocationEnabled) { location_manager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 2000, 2000, listner); location_manager .getLastKnownLocation(LocationManager.GPS_PROVIDER);
public void startLocationUpdates() { GoogleApiAvailability api = GoogleApiAvailability.getInstance(); int status = api.isGooglePlayServicesAvailable(mContext); if (status != ConnectionResult.SUCCESS) { try { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10, 0, this); if (mLocationManager.getAllProviders().contains("network")) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10, 0, this); } mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 10, 0, this); } catch (SecurityException e) { e.printStackTrace(); } } else { // get first position mGoogleApiClient.connect(); } }