List of usage examples for android.location LocationManager getAllProviders
public List<String> getAllProviders()
From source file:Main.java
public static boolean deviceSupportGPS(Context context) { boolean result = false; final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> allProviders = manager.getAllProviders(); if (allProviders.contains(LocationManager.GPS_PROVIDER)) { result = true;/*w ww . j av a 2s . c o m*/ } return result; }
From source file:Main.java
/** * To be used if you just want a one-shot best last location, iterates over * all providers and returns the most accurate result. *///from w w w .ja v a 2 s .c o m public static Location getBestLastGeolocation(Context context) { LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = manager.getAllProviders(); Location bestLocation = null; for (String it : providers) { Location location = manager.getLastKnownLocation(it); if (location != null) { if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) { bestLocation = location; } } } return bestLocation; }
From source file:Main.java
public static boolean supportGps(Context context) { final LocationManager mgr = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (mgr != null) { List<String> providers = mgr.getAllProviders(); return providers != null && providers.contains(LocationManager.GPS_PROVIDER); }/*from w ww .j av a 2 s . c o m*/ return false; }
From source file:Main.java
/** * Checks if the current device has a NETWORK module (hardware) * @return true if the current device has NETWORK *///ww w. j a v a 2 s . c o m public static boolean hasNetworkModule(final Context context) { final LocationManager locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); for (final String provider : locationManager.getAllProviders()) { if (provider.equals(LocationManager.NETWORK_PROVIDER)) { return true; } } return false; }
From source file:uk.ac.horizon.ubihelper.service.channel.LocationChannel.java
public static List<String> getAllProviders(Service service) { LocationManager location = (LocationManager) service.getSystemService(Service.LOCATION_SERVICE); if (location != null) { return location.getAllProviders(); } else {//from w w w.j ava 2 s . c om Log.w(TAG, "No LocationManager"); return new LinkedList<String>(); } }
From source file:it.feio.android.omninotes.utils.GeocodeHelper.java
public static LocationManager getLocationManager(Context context, final LocationListener locationListener) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // A check is done to avoid crash when NETWORK_PROVIDER is not // available (ex. on emulator with API >= 11) if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 50, locationListener); }//from ww w. j ava 2 s . c o m if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER) && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 50, locationListener); } else { locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 60000, 50, locationListener); } return locationManager; }
From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java
public static void registerOnThread(Context context, LocationListener locationCallback, Listener listener) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = locationManager.getAllProviders(); Log.i(TAG, "Found " + providers.size() + " location providers"); for (String provider : providers) { if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Provider " + provider + " enabled"); } else {/*from w w w .j a v a 2 s .c o m*/ Log.i(TAG, "Provider " + provider + " disabled"); } } for (int pi = 0; pi < PROVIDERS.length; pi++) { String provider = PROVIDERS[pi]; if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Registering with provider " + provider); Location loc = locationManager.getLastKnownLocation(provider); if (loc != null) { Log.i(TAG, "Last Location, provider=" + loc.getProvider() + ", lat=" + loc.getLatitude() + ", long=" + loc.getLongitude() + ", bearing=" + (loc.hasBearing() ? "" + loc.getBearing() : "NA") + ", speed=" + (loc.hasSpeed() ? "" + loc.getSpeed() : "NA") + ", accuracy=" + (loc.hasAccuracy() ? "" + loc.getAccuracy() : "NA") + ", alt=" + (loc.hasAltitude() ? "" + loc.getAltitude() : "NA")); ZoneService.updateLocation(context, loc); } //if (!"passive".equals(provider)) if (locationCallback != null) locationManager.requestLocationUpdates(provider, 0/*minTime*/, 0/*minDistance*/, locationCallback); } else Log.e(TAG, "Required provider " + provider + " not enabled!"); } if (listener != null) locationManager.addGpsStatusListener(listener); }
From source file:com.fallahpoor.infocenter.fragments.gps.GpsFragment.java
public boolean hasGpsFeature() { LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); if (locationManager == null) { return false; }// www . j a v a2 s. c o m Iterator<String> iterator = locationManager.getAllProviders().iterator(); String provider; while (iterator.hasNext()) { provider = iterator.next(); if (provider.equals(LocationManager.GPS_PROVIDER)) { return true; } } return false; }
From source file:org.microg.gms.ui.PlacePickerActivity.java
@SuppressWarnings("MissingPermission") private void updateMapFromLocationManager() { LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); Location last = null;/*from w w w . j a v a2 s .co m*/ for (String provider : lm.getAllProviders()) { if (lm.isProviderEnabled(provider)) { Location t = lm.getLastKnownLocation(provider); if (t != null && (last == null || t.getTime() > last.getTime())) { last = t; } } } Log.d(TAG, "Set location to " + last); if (last != null) { mapView.map().setMapPosition(new MapPosition(last.getLatitude(), last.getLongitude(), 4096)); } }
From source file:com.example.scandevice.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getApplicationContext();//w ww . j a v a2 s . com LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); // Getting the name of the provider that meets the criteria provider = locationManager.getBestProvider(criteria, true); if (provider == null && !locationManager.isProviderEnabled(provider)) { // Get the location from the given provider List<String> list = locationManager.getAllProviders(); for (int i = 0; i < list.size(); i++) { //Get device name; String temp = list.get(i); //check usable if (locationManager.isProviderEnabled(temp)) { provider = temp; break; } } } //get location where reference last. Location location = locationManager.getLastKnownLocation(provider); if (location == null) Toast.makeText(this, "There are no available position information providers.", Toast.LENGTH_SHORT) .show(); else //GPS start from last location. onLocationChanged(location); // Set by <content src="index.html" /> in config.xml loadUrl(launchUrl); }