List of usage examples for android.location LocationManager NETWORK_PROVIDER
String NETWORK_PROVIDER
To view the source code for android.location LocationManager NETWORK_PROVIDER.
Click Source Link
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void startGPS() { if (mGPSStarted) { return;/*from ww w . j av a 2 s .co m*/ } if (LocTrigConfig.useMotionDetection) { stopMotionDetection(); } //Get a wake lock for this duty cycle acquireWakeLock(); mNSamples = 0; mPrevSpeed = mCurrSpeed; Log.v(TAG, "LocTrigService: Turning on location updates"); LocationManager locMan = (LocationManager) getSystemService(LOCATION_SERVICE); List<String> providers = locMan.getAllProviders(); if (providers.contains(LocationManager.GPS_PROVIDER)) locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); //Use network location as well if (LocTrigConfig.useNetworkLocation) { if (mWifiLock != null) { if (!mWifiLock.isHeld()) { mWifiLock.acquire(); } } if (providers.contains(LocationManager.NETWORK_PROVIDER)) locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } cancelSamplingAlarm(ACTION_ALRM_GPS_SAMPLE); //Set GPS timeout setSamplingAlarm(ACTION_ALRM_GPS_TIMEOUT, GPS_TIMEOUT, 0); mGPSStarted = true; }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void startGPS() { if (mGPSStarted) { return;/*from www . ja va 2s. c om*/ } if (LocTrigConfig.useMotionDetection) { stopMotionDetection(); } //Get a wake lock for this duty cycle acquireWakeLock(); mNSamples = 0; mPrevSpeed = mCurrSpeed; Log.i(DEBUG_TAG, "LocTrigService: Turning on location updates"); LocationManager locMan = (LocationManager) getSystemService(LOCATION_SERVICE); locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); //Use network location as well if (LocTrigConfig.useNetworkLocation) { if (mWifiLock != null) { if (!mWifiLock.isHeld()) { mWifiLock.acquire(); } } locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } cancelSamplingAlarm(ACTION_ALRM_GPS_SAMPLE); //Set GPS timeout setSamplingAlarm(ACTION_ALRM_GPS_TIMEOUT, GPS_TIMEOUT, 0); mGPSStarted = true; }
From source file:arc.noaa.weather.activities.MainActivity.java
void getCityByLocation() { locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Explanation not needed, since user requests this himself } else {//from w ww. j a v a2s . c o m ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_ACCESS_FINE_LOCATION); } } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { progressDialog = new ProgressDialog(this); progressDialog.setMessage(getString(R.string.getting_location)); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { locationManager.removeUpdates(MainActivity.this); } catch (SecurityException e) { e.printStackTrace(); } } }); progressDialog.show(); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } } else { showLocationSettingsDialog(); } }
From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java
/** * Get the last know position from the GPS provider and return that * information wrapped in a GeoPoint to which the Map can navigate. * * @return// w w w . j a v a2 s. c o m * @see GeoPoint */ private GeoPoint getLastKnowGeopointLocation() { int microLatitude = 0; int microLongitude = 0; LocationManager locationManager = (LocationManager) this.getApplication() .getSystemService(Context.LOCATION_SERVICE); Location locationFine = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (locationFine != null) { microLatitude = (int) (locationFine.getLatitude() * 1E6d); microLongitude = (int) (locationFine.getLongitude() * 1E6d); } if (locationFine == null || microLatitude == 0 || microLongitude == 0) { Location locationCoarse = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (locationCoarse != null) { microLatitude = (int) (locationCoarse.getLatitude() * 1E6d); microLongitude = (int) (locationCoarse.getLongitude() * 1E6d); } if (locationCoarse == null || microLatitude == 0 || microLongitude == 0) { microLatitude = 51985105; microLongitude = 5106132; } } GeoPoint geoPoint = new GeoPoint(microLatitude, microLongitude); return geoPoint; }
From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java
/** * The Location Manager manages location providers. This code searches for * the best provider of data (GPS, WiFi/cell phone tower lookup, some other * mechanism) and finds the last known location. *//*from w w w . j a v a 2s . co m*/ private boolean getLocation() { final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); final String provider = mLocationManager.getBestProvider(criteria, true); if (provider != null) { final Location location; if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } else { location = mLocationManager.getLastKnownLocation(provider); } if (location == null) { mLocationManager.requestLocationUpdates(provider, 0, 0, this); setProgressVisibility(true); } mRecentLocation = location != null ? new ParcelableLocation(location) : null; } else { Crouton.showText(this, R.string.cannot_get_location, CroutonStyle.ALERT); } return provider != null; }
From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java
public Location lastKnownLocation() { Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null || (location.getLatitude() == 0.0 && location.getLongitude() == 0.0)) { location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location == null || (location.getLatitude() == 0.0 && location.getLongitude() == 0.0)) { }/* ww w. j av a2 s . c om*/ } return location; }
From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java
/** * checks if location services are available */// www . j av a 2 s . com public static boolean isGPSAvailable(Context context) { if (context == null) { return false; } LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return manager.isProviderEnabled(LocationManager.GPS_PROVIDER) || manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); }
From source file:com.corporatetaxi.TaxiArrived_Acitivity.java
public Location getLocation() { try {/*from w w w . j a va2 s . c o m*/ map.setMyLocationEnabled(true); locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE); // getting GPS status isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); // getting network status isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { // no network provider is enabled } else { this.canGetLocation = true; // First get location from Network Provider if (isNetworkEnabled) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); Log.d("Network", "Network"); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { lat = location.getLatitude(); lon = location.getLongitude(); } } } // if GPS Enabled get lat/long using GPS Services if (isGPSEnabled) { if (location == null) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); Log.d("GPS Enabled", "GPS Enabled"); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { lat = location.getLatitude(); lon = location.getLongitude(); } } } } } } catch (Exception e) { e.printStackTrace(); } return location; }
From source file:com.cs528.style.style.weather.WeatherActivity.java
void getCityByLocation() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) { // Explanation not needed, since user requests this himself } else {/*from w w w. ja v a 2 s .c om*/ ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_ACCESS_FINE_LOCATION); } } else { progressDialog.setMessage(getString(R.string.getting_location)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.show(); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } }
From source file:com.vonglasow.michael.satstat.ui.MapSectionFragment.java
/** * Updates the list of styles to use for the location providers. * // w ww . j av a2 s . c o m * This method updates the internal list of styles to use for displaying * locations on the map, assigning a style to each location provider. * Styles that are defined in {@link SharedPreferences} are preserved. If * none are defined, the GPS location provider is assigned the red style * and the network location provider is assigned the blue style. The * passive location provider is not assigned a style, as it does not send * any locations of its own. Other location providers are assigned one of * the following styles: green, orange, purple. If there are more location * providers than styles, the same style (including red and blue) can be * assigned to multiple providers. The mapping is written to * SharedPreferences so that it will be preserved even as available * location providers change. */ public void updateLocationProviderStyles() { //FIXME: move code into assignLocationProviderStyle and use that List<String> allProviders = mainActivity.locationManager.getAllProviders(); allProviders.remove(LocationManager.PASSIVE_PROVIDER); if (allProviders.contains(LocationManager.GPS_PROVIDER)) { providerStyles.put(LocationManager.GPS_PROVIDER, mainActivity.mSharedPreferences.getString( Const.KEY_PREF_LOC_PROV_STYLE + LocationManager.GPS_PROVIDER, Const.LOCATION_PROVIDER_RED)); mAvailableProviderStyles.remove(Const.LOCATION_PROVIDER_RED); allProviders.remove(LocationManager.GPS_PROVIDER); } if (allProviders.contains(LocationManager.NETWORK_PROVIDER)) { providerStyles.put(LocationManager.NETWORK_PROVIDER, mainActivity.mSharedPreferences.getString( Const.KEY_PREF_LOC_PROV_STYLE + LocationManager.NETWORK_PROVIDER, Const.LOCATION_PROVIDER_BLUE)); mAvailableProviderStyles.remove(Const.LOCATION_PROVIDER_BLUE); allProviders.remove(LocationManager.NETWORK_PROVIDER); } for (String prov : allProviders) { if (mAvailableProviderStyles.isEmpty()) mAvailableProviderStyles.addAll(Arrays.asList(Const.LOCATION_PROVIDER_STYLES)); providerStyles.put(prov, mainActivity.mSharedPreferences.getString(Const.KEY_PREF_LOC_PROV_STYLE + prov, mAvailableProviderStyles.get(0))); mAvailableProviderStyles.remove(providerStyles.get(prov)); } ; SharedPreferences.Editor spEditor = mainActivity.mSharedPreferences.edit(); for (String prov : providerStyles.keySet()) spEditor.putString(Const.KEY_PREF_LOC_PROV_STYLE + prov, providerStyles.get(prov)); spEditor.commit(); }