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:net.frakbot.FWeather.util.LocationHelper.java
private static boolean isLowPowerLocationProviderEnabled() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try {// w w w .jav a 2s . com int activeMode = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE); return (activeMode & Settings.Secure.LOCATION_MODE_BATTERY_SAVING) != 0; } catch (Settings.SettingNotFoundException e) { FLog.w(TAG, "Unable to detect the location mode using the new 4.4+ APIs, " + "falling back on the old ones."); return false; } } @SuppressWarnings("deprecation") String availProviders = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); return availProviders != null && (availProviders.contains(LocationManager.NETWORK_PROVIDER) || availProviders.contains(LocationManager.PASSIVE_PROVIDER)); }
From source file:com.magicmod.mmweather.MainActivity.java
private void updateByGeoLocation() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); Log.d(TAG, "Current location is " + location); boolean needsUpdate = location == null; if (location == null) { Toast.makeText(mContext, mContext.getString(R.string.geo_location_fail_info), Toast.LENGTH_LONG).show(); }/*from ww w .j a va 2 s . c o m*/ if (location != null) { long delta = System.currentTimeMillis() - location.getTime(); needsUpdate = delta > Constants.OUTDATED_LOCATION_THRESHOLD_MILLIS; } if (needsUpdate) { // TODO: use a better way to get location } if (location != null) { new WeatherUpdateTask(location, Preferences.isMetric(mContext)).execute(); } }
From source file:org.noise_planet.noisecapture.MeasurementService.java
private void initPassive() { if (passiveLocationListener == null) { passiveLocationListener = new CommonLocationListener(this, LISTENER.PASSIVE); }/*from ww w.j a v a 2s . c o m*/ passiveLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && passiveLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) { passiveLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, minTimeDelay, 0, passiveLocationListener); } }
From source file:de.grobox.liberario.StationsFragment.java
private void getLocation() { pd = new ProgressDialog(getActivity()); pd.setMessage(getResources().getString(R.string.stations_searching_position)); pd.setCancelable(false);/*from w w w .java 2 s . co m*/ pd.setIndeterminate(true); pd.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeUpdates(); dialog.dismiss(); } }); pd.show(); 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))) { removeUpdates(); pd.dismiss(); Toast.makeText(getActivity(), getResources().getString(R.string.error_no_location_provider), Toast.LENGTH_LONG).show(); } loc_found = false; }
From source file:com.forrestguice.suntimeswidget.getfix.GetFixHelper.java
public static boolean isPassiveProviderEnabled(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER); }
From source file:org.noise_planet.noisecapture.MeasurementService.java
private void stopGPS() { if (gpsLocationListener == null || gpsLocationManager == null) { return;// w ww .j a v a2s. c o m } if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && passiveLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) { gpsLocationManager.removeUpdates(gpsLocationListener); } }
From source file:com.landenlabs.all_devtool.GpsFragment.java
@SuppressWarnings("deprecation") @Override//from ww w .j ava 2 s .c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); View rootView = inflater.inflate(R.layout.gps_tab, container, false); m_statusIcon = Ui.viewById(rootView, R.id.gpsStatus); m_statusIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); Ui.viewById(rootView, R.id.gps_clear).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clearList(); } }); m_list.clear(); // ---- Get UI components ---- for (int idx = 0; idx != s_maxRows; idx++) m_list.add(null); m_list.set(s_providersRow, new GpsInfo(new GpsItem("Providers"))); m_list.set(s_lastUpdateRow, new GpsInfo(new GpsItem("Last Update"))); m_list.set(s_detailRow, new GpsInfo(new GpsItem("Detail History"))); m_listView = Ui.viewById(rootView, R.id.gpsListView); final GpsArrayAdapter adapter = new GpsArrayAdapter(this.getActivity()); m_listView.setAdapter(adapter); // ---- Setup GPS ---- m_locMgr = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); m_gpsTv = Ui.viewById(rootView, R.id.gps); if (isGooglePlayServicesAvailable()) { m_locationRequest = new LocationRequest(); m_locationRequest.setInterval(GPS_INTERVAL); m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL); // Priority needs to match permissions. // Use LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY with // <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> // Use LocationRequest.PRIORITY_HIGH_ACCURACY with // <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> m_locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); m_googleApiClient = new GoogleApiClient.Builder(this.getActivity()).addApi(LocationServices.API) .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); m_gpsTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { m_gpsMonitor = !m_gpsMonitor; view.setSelected(m_gpsMonitor); addMsgToDetailRow(s_colorMsg, m_gpsMonitor ? "Start Monitor" : "Stop Monitor"); showProviders(); } }); } else { m_gpsTv.setText("Need Google Play Service"); } if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { m_locMgr.addGpsStatusListener(this); } /* http://stackoverflow.com/questions/11398732/how-do-i-receive-the-system-broadcast-when-gps-status-has-changed <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <receiver android:name=".GpsReceiver"> <intent-filter> <action android:name="android.location.GPS_ENABLED_CHANGE" /> <action android:name="android.location.PROVIDERS_CHANGED" /> </intent-filter> </receiver> */ // GpsReceiver m_gpsReceiver = new GpsReceiver(); m_intentFilter.addAction(GpsReceiver.GPS_ENABLED_CHANGE_ACTION); if (Build.VERSION.SDK_INT >= 19) { m_intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); } m_intentFilter.addAction(GpsReceiver.GPS_FIX_CHANGE_ACTION); m_intentFilter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION); showProviders(); // TODO - get available providers getCheckBox(rootView, R.id.gpsFuseCb, FUSED_PROVIDER); getCheckBox(rootView, R.id.gpsGPSCb, LocationManager.GPS_PROVIDER); getCheckBox(rootView, R.id.gpsNetwkCb, LocationManager.NETWORK_PROVIDER); getCheckBox(rootView, R.id.gpsLowPwrCb, LocationManager.PASSIVE_PROVIDER); getCheckBox(rootView, R.id.gpsStatusCb, STATUS_CB); for (CheckBox cb : m_providersCb.values()) { cb.setOnClickListener(this); } initLastUpdate(); // Expand All for (int idx = 0; idx != s_maxRows; idx++) m_listView.expandGroup(idx); return rootView; }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
/** */*from w w w .j a v a 2 s . co m*/ * @param value set true to engage "aggressive", battery-consuming tracking, false for stationary-region tracking */ private void setPace(Boolean value) { Log.i(TAG, "setPace: " + value); Boolean wasMoving = isMoving; isMoving = value; isAcquiringStationaryLocation = false; isAcquiringSpeed = false; stationaryLocation = null; locationManager.removeUpdates(this); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setHorizontalAccuracy(translateDesiredAccuracy(desiredAccuracy)); criteria.setPowerRequirement(Criteria.POWER_HIGH); if (isMoving) { // setPace can be called while moving, after distanceFilter has been recalculated. We don't want to re-acquire velocity in this case. if (!wasMoving) { isAcquiringSpeed = true; } } else { isAcquiringStationaryLocation = true; } // Temporarily turn on super-aggressive geolocation on all providers when acquiring velocity or stationary location. if (isAcquiringSpeed || isAcquiringStationaryLocation) { locationAcquisitionAttempts = 0; // Turn on each provider aggressively for a short period of time List<String> matchingProviders = locationManager.getAllProviders(); for (String provider : matchingProviders) { if (provider != LocationManager.PASSIVE_PROVIDER) { locationManager.requestLocationUpdates(provider, 0, 0, this); } } } else { locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), locationTimeout * 1000, scaledDistanceFilter, this); } }
From source file:org.noise_planet.noisecapture.MeasurementService.java
private void stopPassive() { if (passiveLocationListener == null || passiveLocationManager == null) { return;// www . ja v a 2 s . c om } passiveLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && passiveLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) { passiveLocationManager.removeUpdates(passiveLocationListener); } }
From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java
/** * Sets up the Google Map Fragment/*w w w.ja va2 s . co m*/ */ private void setupGoogleMap() { LocationManager lm = (LocationManager) getMainActivity().getSystemService(Context.LOCATION_SERVICE); //check for permissions and get last known location of the device if (ActivityCompat.checkSelfPermission(getMainActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getMainActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { getMainActivity().checkPermissions(); this.lastKnownLoc = lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } else { this.lastKnownLoc = lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } }