List of usage examples for android.location LocationManager PASSIVE_PROVIDER
String PASSIVE_PROVIDER
To view the source code for android.location LocationManager PASSIVE_PROVIDER.
Click Source Link
From source file:Main.java
public static void beginListening(Context ctx, LocationListener ll) { LocationManager lm = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); if (lm.getProvider(LocationManager.GPS_PROVIDER) != null) { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); } else if (lm.getProvider(LocationManager.NETWORK_PROVIDER) != null) { lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll); } else {/*from ww w .ja v a 2 s .c om*/ lm.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, ll); } }
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); }/* w w w . j av a 2 s.c om*/ 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:org.mozilla.mozstumbler.service.stumblerthread.scanners.GPSScanner.java
private void startPassiveMode() { LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (!isGpsAvailable(locationManager)) { return;//from w w w .j a va 2s . c o m } locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this); final int timeDiffSec = Long.valueOf((System.currentTimeMillis() - mTelemetry_lastStartedMs) / 1000) .intValue(); if (mTelemetry_lastStartedMs > 0 && timeDiffSec > 0) { TelemetryWrapper.addToHistogram(AppGlobals.TELEMETRY_TIME_BETWEEN_STARTS_SEC, timeDiffSec); } mTelemetry_lastStartedMs = System.currentTimeMillis(); }
From source file:com.laocuo.weather.presenter.impl.LocationPresenter.java
public String requestLocation() { String city = null;//from w w w . jav a 2 s.c om if (!checkLocationPermission(mContext)) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. requestLocationPermission((Activity) mContext); return null; } Location l = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (l != null) { L.d("getLastKnownLocation"); city = saveCityByLocation(l); } else { L.d("requestSingleUpdate"); if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { mView.openLocation(); mLocationManager.requestSingleUpdate(LocationManager.PASSIVE_PROVIDER, mLocationListener, null); } else { mLocationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, mLocationListener, null); } } return city; }
From source file:ru.dublgis.androidlocation.PassiveLocationProvider.java
static public Location lastKnownPosition(boolean fromSatelliteOnly) { Log.i(TAG, "lastKnownPosition"); try {/*from w ww . j av a 2s .co m*/ if (null != mContext && null != mLocationManager && isPermissionGranted(mContext)) { Log.i(TAG, "lastKnownPosition, mLocationManager not null"); return mLocationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } } catch (Throwable e) { Log.e(TAG, "Failed to get last known position", e); } Log.i(TAG, "lastKnownPosition, return null"); return null; }
From source file:de.grobox.liberario.ui.LocationInputGPSView.java
public void activateGPS() { if (isSearching()) return;//from ww w. j a va 2 s . co m // check permissions if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // we don't have a permission, so store the information that we are requesting it request_permission = true; // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.ACCESS_FINE_LOCATION)) { Toast.makeText(context, R.string.permission_denied_gps, Toast.LENGTH_LONG).show(); } else { // No explanation needed, we can request the permission ActivityCompat.requestPermissions(context, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, caller); } return; } // we arrive here only once we have got the permission and are not longer requesting it request_permission = false; List<String> providers = locationManager.getProviders(true); for (String provider : providers) { // Register the listener with the Location Manager to receive location updates locationManager.requestSingleUpdate(provider, this, null); Log.d(getClass().getSimpleName(), "Register provider for location updates: " + provider); } // check if there is a non-passive provider available if (providers.size() == 0 || (providers.size() == 1 && providers.get(0).equals(LocationManager.PASSIVE_PROVIDER))) { locationManager.removeUpdates(this); Toast.makeText(context, context.getResources().getString(R.string.error_no_location_provider), Toast.LENGTH_LONG).show(); return; } // clear input //noinspection deprecation setLocation(null, context.getResources().getDrawable(R.drawable.ic_gps)); ui.clear.setVisibility(View.VISIBLE); // clear current GPS location, because we are looking to find a new one gps_location = null; // show GPS button blinking final Animation animation = new AlphaAnimation(1, 0); animation.setDuration(500); animation.setInterpolator(new LinearInterpolator()); animation.setRepeatCount(Animation.INFINITE); animation.setRepeatMode(Animation.REVERSE); ui.status.setAnimation(animation); ui.location.setHint(R.string.stations_searching_position); ui.location.clearFocus(); searching = true; }
From source file:us.dustinj.locationstore.LocationService.java
@Override public void onCreate() { Log.d(this.getClass().getSimpleName(), "onCreate"); m_appSettings = AppSettings.GetSettings(this); m_locationDatabase = new LocationDatabase(this); m_locationAggregator = new LocationAggregator(m_appSettings, m_locationDatabase); m_exportStateMachine = ExportStateMachine.makeStateMachine(this, m_appSettings.GetTimers()); m_forcedFixStateMachine = ForcedFixStateMachine.makeStateMachine(this, m_appSettings); m_gcmRegistrationStateMachine = GcmRegistrationStateMachine.makeStateMachine(this, m_appSettings.GetTimers());/*from w w w .j a v a 2 s. c o m*/ m_locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); m_locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 1000, (float) 0.1, this); m_connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); LocalBroadcastManager.getInstance(this).registerReceiver(m_gcmRegistrationChangeReceiver, new IntentFilter("gcm_registrationIdChanged")); LocalBroadcastManager.getInstance(this).registerReceiver(m_gcmMessageIntentReceiver, new IntentFilter("gcm_messageReceived")); GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, CommonUtilities.SENDER_ID); } else { Log.v(this.getClass().getSimpleName(), "Already registered"); } Log.d(this.getClass().getSimpleName(), "regId: " + regId); }
From source file:org.traccar.client.ShortcutActivity.java
@SuppressWarnings("MissingPermission") private void sendAlarm() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); String provider = PositionProvider.getProvider(preferences.getString(MainFragment.KEY_ACCURACY, "medium")); try {// w w w .j a v a2 s. com Location location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); if (location != null) { sendAlarmLocation(location); } else { locationManager.requestSingleUpdate(provider, new LocationListener() { @Override public void onLocationChanged(Location location) { sendAlarmLocation(location); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }, Looper.myLooper()); } } catch (RuntimeException e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:planets.position.NewLoc.java
/** * Gets the GPS location of the device or loads test values. *//*from w ww . j av a 2 s .com*/ private void getLocation() { // get lat/long from GPS loc = null; gpsTask = new GetGPSTask(); gpsTask.execute(); boolean result = userLocation.getLocation(this, locationResult); if (!result) { loc = new Location(LocationManager.PASSIVE_PROVIDER); } }
From source file:com.geoffreybuttercrumbs.arewethereyet.ZonePicker.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); setContentView(R.layout.main);// w w w .j a v a2s . com // Setup the map setUpMapIfNeeded(); AlarmOverlay alarmView = (AlarmOverlay) findViewById(R.id.alarm_overlay); alarmView.setMap(mMap, this); // Set the Behind View setBehindContentView(R.layout.menu_frame); FragmentTransaction t = this.getSupportFragmentManager().beginTransaction(); mFrag = new DrawerFragment(); t.replace(R.id.menu_frame, mFrag); t.commit(); // customize the SlidingMenu SlidingMenu sm = getSlidingMenu(); sm.setShadowWidthRes(R.dimen.shadow_width); sm.setShadowDrawable(R.drawable.shadow); sm.setBehindOffsetRes(R.dimen.slidingmenu_offset); sm.setFadeDegree(0.35f); sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); getSupportActionBar().setDisplayHomeAsUpEnabled(true); //Stop existing alarms stopService(new Intent(ZonePicker.this, AlarmService.class)); //Reset to default ring tone. (Otherwise it is silent!) initTone(); // Acquire a reference to the system Location Manager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); crit.setAccuracy(Criteria.ACCURACY_FINE); Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, updateRange, this); //If system has a last known location, use that... if (lastKnownLocation != null) { zone = new Zone(lastKnownLocation, 1000); animateTo(zone.getLocation()); alarmView.setZone(zone); } //Else use an arbitrary point else { Location tempLocation = new Location(""); tempLocation.setLatitude(42.36544); tempLocation.setLongitude(-71.103644); zone = new Zone(tempLocation, 1000); animateTo(zone.getLocation()); alarmView.setZone(zone); } getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black)); }