List of usage examples for android.location Criteria setPowerRequirement
public void setPowerRequirement(int level)
From source file:com.zainsoft.ramzantimetable.QiblaActivity.java
private void registerForGPS() { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false);/* w ww .ja va 2s. c om*/ criteria.setSpeedRequired(false); criteria.setCostAllowed(true); LocationManager locationManager = ((LocationManager) getSystemService(Context.LOCATION_SERVICE)); String provider = locationManager.getBestProvider(criteria, true); if (provider != null) { locationManager.requestLocationUpdates(provider, MIN_LOCATION_TIME, MIN_LOCATION_DISTANCE, qiblaManager); } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_LOCATION_TIME, MIN_LOCATION_DISTANCE, qiblaManager); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_LOCATION_TIME, MIN_LOCATION_DISTANCE, qiblaManager); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null) { location = ((LocationManager) getSystemService(Context.LOCATION_SERVICE)) .getLastKnownLocation(LocationManager.GPS_PROVIDER); } if (location != null) { qiblaManager.onLocationChanged(location); } }
From source file:com.fpil.android.remotesensor.MainDisplay.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Criteria locationCriteria = new Criteria(); locationCriteria.setAccuracy(Criteria.ACCURACY_FINE); locationCriteria.setAltitudeRequired(false); locationCriteria.setBearingRequired(false); locationCriteria.setCostAllowed(true); locationCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT); locationProviderName = locationManager.getBestProvider(locationCriteria, true); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); this.startActivity(myIntent); }/*from w ww . ja v a 2s . c o m*/ if (locationProviderName != null && locationManager.isProviderEnabled(locationProviderName)) { // Provider is enabled Toast.makeText(getActivity(), R.string.gps_available, Toast.LENGTH_LONG).show(); } else { // Provider not enabled, prompt user to enable it Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); this.startActivity(myIntent); } }
From source file:net.jongrakko.zipsuri.activity.PostUploadActivity.java
@Override public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) { if (isChecked) { switch (buttonView.getId()) { case R.id.radioButtonAddressGPS: mEditTextAddress.setOnClickListener(null); this.mGoogleMap.setOnMapClickListener(this); this.mGoogleMap.setOnMyLocationButtonClickListener(this); if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mGoogleMap.setMyLocationEnabled(true); LocationProvider lprovider; LocationManager lm = (LocationManager) getActivity() .getSystemService(getActivity().LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); String provider;/* www . ja va 2 s . co m*/ Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); provider = lm.getBestProvider(criteria, true); if (provider == null || provider.equals("passive")) { // ? ? ?? new AlertDialog.Builder(getActivity()).setTitle(" ??") .setNeutralButton("??", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { buttonView.toggle(); startActivityForResult( new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); } }).show(); } else { // ? ? lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this); Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (l != null) { Log.e("hello??", "okok"); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, MY_LOCATION_REQUEST_CODE); } } break; case R.id.radioButtonAddressSelf: this.mGoogleMap.setOnMapClickListener(null); mEditTextAddress.setOnClickListener(this); this.mGoogleMap.setOnMyLocationButtonClickListener(null); mGoogleMap.setMyLocationEnabled(false); mEditTextAddress.setOnClickListener(this); startActivityForResult(new Intent(getContext(), SearchAddressActivity.class), SEARCH_ADDRESS); break; } } }
From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java
private final void init_location() { pref_app = PreferenceManager.getDefaultSharedPreferences(this); new Thread(new Runnable() { @Override/*from w ww.ja v a 2s .c om*/ public final void run() { try { final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (mLocationManager != null) { // final String provider = manager.getBestProvider(criteria, true); boolean provider_flag = false; final List<String> providers = mLocationManager.getProviders(true); for (final String provider : providers) { if ((provider.equals(LocationManager.GPS_PROVIDER)) || (provider.equals(LocationManager.NETWORK_PROVIDER))) { if (mLocationManager.isProviderEnabled(provider)) { provider_flag = true; } } WriteLog.write(UpdateTweetDrive.this, "requestLocationUpdates() provider: " + provider); final int pref_locationinfo_mintime = ListAdapter.getPrefInt(UpdateTweetDrive.this, "pref_locationinfo_mintime", "300000"); try { new Runnable() { @Override public final void run() { if (ContextCompat.checkSelfPermission(UpdateTweetDrive.this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mLocationManager.requestLocationUpdates(provider, pref_locationinfo_mintime, 0, UpdateTweetDrive.this); } else { if (Build.VERSION.SDK_INT >= 23) requestPermissions( new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_PERMISSION); } } }; } catch (final Exception e) { WriteLog.write(UpdateTweetDrive.this, e); } } if (startup_flag == true) { startup_flag = false; if (provider_flag == false) { toast(getString(R.string.open_location_source_settings)); try { startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS")); } catch (final ActivityNotFoundException e) { WriteLog.write(UpdateTweetDrive.this, e); } catch (final Exception e) { WriteLog.write(UpdateTweetDrive.this, e); } } } } } catch (final IllegalArgumentException e) { WriteLog.write(UpdateTweetDrive.this, e); } catch (final RuntimeException e) { WriteLog.write(UpdateTweetDrive.this, e); } } }).start(); }
From source file:name.gumartinm.weather.information.activity.MapActivity.java
public void onClickGetLocation(final View v) { // TODO: Somehow I should show a progress dialog. // If Google Play Services is available if (this.mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { // TODO: Hopefully there will be results even if location did not change... final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingAccuracy(Criteria.NO_REQUIREMENT); criteria.setBearingRequired(false); criteria.setCostAllowed(false);/* w ww .j a v a 2 s .c o m*/ criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH); criteria.setPowerRequirement(Criteria.POWER_MEDIUM); criteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT); criteria.setSpeedRequired(false); criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH); this.mLocationManager.requestSingleUpdate(criteria, this, null); } else { Toast.makeText(this, this.getString(R.string.weather_map_not_enabled_location), Toast.LENGTH_LONG) .show(); } // Trying to use the synchronous calls. Problems: mGoogleApiClient read/store from different threads. // new GetLocationTask(this).execute(); }
From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java
/** * Get provider name.//from w w w. j av a 2s . c o m * @return Name of best suiting provider. * */ String getProviderName() { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setPowerRequirement(Criteria.POWER_LOW); // Chose your desired power consumption level. criteria.setAccuracy(Criteria.ACCURACY_FINE); // Choose your accuracy requirement. criteria.setSpeedRequired(false); // Chose if speed for first location fix is required. criteria.setAltitudeRequired(false); // Choose if you use altitude. criteria.setBearingRequired(false); // Choose if you use bearing. criteria.setCostAllowed(false); // Choose if this provider can waste money :-) // Provide your criteria and flag enabledOnly that tells // LocationManager only to return active providers. return locationManager.getBestProvider(criteria, true); }
From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java
/********************************* * /*www .ja va 2s.c o m*/ * Constructor * @param context * *********************************/ public LastFmEventImporter(Context context) { this.context = context; Log.i("LASTFMEVENT", "creating-------------------------"); /* * Check for Internet Connection (Through whichever interface) */ ConnectivityManager connManager = (ConnectivityManager) ((RockPlayer) context) .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connManager.getActiveNetworkInfo(); /******* EMULATOR HACK - false condition needs to be removed *****/ //if (false && (netInfo == null || !netInfo.isConnected())){ if ((netInfo == null || !netInfo.isConnected())) { Bundle data = new Bundle(); data.putString("info", "No Internet Connection"); Message msg = new Message(); msg.setData(data); ((RockPlayer) context).analyseConcertInfoHandler.sendMessage(msg); return; } /* * Get location */ MIN_UPDATE_INTVL = 5 * 24 * 60 * 60 * 1000; // 5 days SPREAD_INTVL = 21 * 24 * 60 * 60 * 1000; // 21 days; Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locManager.getBestProvider(criteria, true) != null) myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(criteria, true)); else { myLocation = new Location("gps"); myLocation.setLatitude(47.100301); myLocation.setLongitude(-119.982465); } /* * Get preferred distance */ // SharedPreferences prefs = ((Filex) context).getSharedPreferences(((Filex) context).PREFS_NAME, 0); RockOnPreferenceManager prefs = new RockOnPreferenceManager(((RockPlayer) context).FILEX_PREFERENCES_PATH); concertRadius = prefs.getLong("ConcertRadius", (long) (((RockPlayer) context).CONCERT_RADIUS_DEFAULT)); //myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(Criteria.POWER_LOW, true)); // try { // getArtistEvents(); // } catch (SAXException e) { // e.printStackTrace(); // } catch (ParserConfigurationException e) { // e.printStackTrace(); // } }
From source file:com.google.ytd.SubmitActivity.java
private void getVideoLocation() { this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false);// w w w .j a v a 2s .co m criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); this.locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (location != null) { SubmitActivity.this.videoLocation = location; double lat = location.getLatitude(); double lng = location.getLongitude(); Log.d(LOG_TAG, "lat=" + lat); Log.d(LOG_TAG, "lng=" + lng); TextView locationText = (TextView) findViewById(R.id.locationLabel); locationText.setText("Geo Location: " + String.format("lat=%.2f lng=%.2f", lat, lng)); locationManager.removeUpdates(this); } else { Log.d(LOG_TAG, "location is null"); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }; if (provider != null) { locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } }
From source file:pandroid.agent.PandroidAgentListener.java
private void gpsLocation() { // Starts with GPS, if no GPS then gets network location // /*from w w w. j a v a2 s .c o m*/ LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Log.d("PANDROID providers count", "" + providers.size()); /* Loop over the array backwards, and if you get an accurate location, then break out the loop*/ Location loc = null; for (int i = providers.size() - 1; i >= 0; i--) { Log.d("PANDROID providers", providers.get(i)); loc = lm.getLastKnownLocation(providers.get(i)); if (loc != null) break; } if (loc != null) { Log.d("PANDROID", "loc != null"); //if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) { lastGpsContactDateTime = getHumanDateTime(-1); //`} Log.d("LATITUDE", Double.valueOf(loc.getLatitude()).toString()); Log.d("LONGITUDE", Double.valueOf(loc.getLongitude()).toString()); putSharedData("PANDROID_DATA", "latitude", Double.valueOf(loc.getLatitude()).toString(), "float"); putSharedData("PANDROID_DATA", "longitude", Double.valueOf(loc.getLongitude()).toString(), "float"); } Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); String bestProvider = lm.getBestProvider(criteria, true); // If not provider found, abort GPS retrieving if (bestProvider == null) { Log.e("LOCATION", "No location provider found!"); return; } lm.requestLocationUpdates(bestProvider, Core.interval, 15, new LocationListener() { public void onLocationChanged(Location location) { Log.d("Best latitude", Double.valueOf(location.getLatitude()).toString()); putSharedData("PANDROID_DATA", "latitude", Double.valueOf(location.getLatitude()).toString(), "float"); Log.d("Best longitude", Double.valueOf(location.getLongitude()).toString()); putSharedData("PANDROID_DATA", "longitude", Double.valueOf(location.getLongitude()).toString(), "float"); } public void onStatusChanged(String s, int i, Bundle bundle) { } public void onProviderEnabled(String s) { // try switching to a different provider } public void onProviderDisabled(String s) { putSharedData("PANDROID_DATA", "enabled_location_provider", "disabled", "string"); } }); //} }
From source file:com.BeatYourRecord.SubmitActivity.java
private void getVideoLocation() { this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false);/*w w w.ja v a2s .c o m*/ criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); this.locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (location != null) { SubmitActivity.this.videoLocation = location; lat = location.getLatitude(); lng = location.getLongitude(); Log.d(LOG_TAG, "lat=" + lat); Log.d(LOG_TAG, "lng=" + lng); TextView locationText = (TextView) findViewById(R.id.locationLabel); locationText.setText("Geo Location: " + String.format("lat=%.2f lng=%.2f", lat, lng)); locationManager.removeUpdates(this); } else { Log.d(LOG_TAG, "location is null"); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }; if (provider != null) { locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } }