List of usage examples for android.location Criteria POWER_LOW
int POWER_LOW
To view the source code for android.location Criteria POWER_LOW.
Click Source Link
From source file:Main.java
public static Criteria getGeoCriteria() { if (criteria == null) criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_MEDIUM); criteria.setPowerRequirement(Criteria.POWER_LOW); return criteria; }
From source file:com.appdynamics.demo.gasp.utils.LocationServices.java
/** * Set Location Services and get current location *///w w w.j a va2 s . co m public static Location getLocation(Context context) { Location location = null; try { String svcName = Context.LOCATION_SERVICE; LocationManager locationManager = (LocationManager) context.getSystemService(svcName); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); Log.i(TAG, "Current Latitude = " + location.getLatitude()); Log.i(TAG, "Current Longitude = " + location.getLongitude()); } catch (Exception e) { e.printStackTrace(); } return location; }
From source file:net.quranquiz.ui.QQMap.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map);//from w w w . j a v a 2 s.c om map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); map.setOnMarkerClickListener((OnMarkerClickListener) this); cairo = new LatLng(30.1, 31.45); LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER); // Check if enabled and if not send user to the GSP settings // Better solution would be to display a dialog and suggesting to // go to the settings if (!enabledGPS) { Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show(); startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { Toast.makeText(this, "Selected Provider " + provider, Toast.LENGTH_SHORT).show(); meMarker = map.addMarker( new MarkerOptions().position(cairo).title("That's Me").snippet("a normal QuranQuiz Node!") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))); map.moveCamera(CameraUpdateFactory.newLatLngZoom(cairo, 12.0f)); onLocationChanged(location); } else { //do something } }
From source file:com.findcab.driver.activity.Signup.java
private void initView() { context = this; back = (Button) findViewById(R.id.back); back.setOnClickListener(this); start = (Button) findViewById(R.id.start); start.setOnClickListener(this); edit_name = (EditText) findViewById(R.id.name); edit_mobile = (EditText) findViewById(R.id.mobile); edit_password = (EditText) findViewById(R.id.password); checkBox = (CheckBox) findViewById(R.id.checkBox); item = (TextView) findViewById(R.id.item); item.setOnClickListener(this); if (initGPS()) { LocationManager locationManager; String serviceName = Context.LOCATION_SERVICE; locationManager = (LocationManager) this.getSystemService(serviceName); // ?//from w ww.j ava 2 s . co m Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); String provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); if (location != null) { lat = location.getLatitude(); lng = location.getLongitude(); } } }
From source file:com.careme.apvereda.careme.AccumulatorService.java
@Override public int onStartCommand(Intent intenc, int flags, int idArranque) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences("basicData", Context.MODE_PRIVATE); String email = sharedPref.getString("email", ""); //Uncomment to use Nimbees features /*if (email.compareTo("") != 0) { try {//w w w.j a v a 2 s . co m // Initialize library calling the init method on the Nimbees Client NimbeesClient.init(this); } catch (NimbeesException e) { e.printStackTrace(); } NimbeesClient.getUserManager().register("email", new NimbeesRegistrationCallback() { @Override public void onSuccess() { /* Registration was successful! Toast.makeText(getApplicationContext(), "xito en el registro", Toast.LENGTH_LONG).show(); } @Override public void onFailure(NimbeesException failure) { /* Registration failed Toast.makeText(getApplicationContext(), "Fallo en el registro", Toast.LENGTH_LONG).show(); } }); } */ //Toast.makeText(this,"Servicio arrancado "+ idArranque, Toast.LENGTH_SHORT).show(); // Obtain a reference to the Location Manager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); crit.setPowerRequirement(Criteria.POWER_LOW); provider = locManager.getBestProvider(crit, true); // And register to obtain current location updates locListener = new LocationListener() { public void onLocationChanged(Location loc) { // Insert a new entry on History History history = new History(loc.getLatitude(), loc.getLongitude(), new Date()); db.insertHistory(history); //Uncomment to use Nimbees features /* try { sendPersonalizado(loc); } catch (Exception e) { }*/ /* Monitor makes the monitoring of the user to determine if he/she has lost */ monitor(loc); } @Override public void onStatusChanged(String provider, int stat, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; // We want to update the current location every time the user moves MIN_DISTANCE locManager.requestLocationUpdates(provider, 0, MIN_DISTANCE, locListener); return START_STICKY; }
From source file:ca.mudar.mtlaucasou.LocationFragmentActivity.java
@Override public void onCreate(Bundle savedInstanceState) { mAppHelper = (AppHelper) getApplicationContext(); mActivityHelper = ActivityHelper.createInstance(this); prefs = getSharedPreferences(Const.APP_PREFS_NAME, Context.MODE_PRIVATE); prefsEditor = prefs.edit();/*from ww w .j av a 2s . c o m*/ locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); /** * Instantiate a LastLocationFinder class. This will be used to find the * last known location when the application starts. */ lastLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this); lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener); hasRegisteredSingleUpdateReceiver = true; /** * Set the last known location as user's current location. */ mAppHelper.setLocation(lastLocationFinder.getLastBestLocation(Const.MAX_DISTANCE, Const.MAX_TIME)); /** * Specify the Criteria to use when requesting location updates while * the application is Active. */ criteria = new Criteria(); if (Const.USE_GPS_WHEN_ACTIVITY_VISIBLE) { criteria.setAccuracy(Criteria.ACCURACY_FINE); } else { criteria.setPowerRequirement(Criteria.POWER_LOW); } /** * Setup the location update Pending Intents. */ Intent activeIntent = new Intent(this, LocationChangedReceiver.class); locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent passiveIntent = new Intent(this, PassiveLocationChangedReceiver.class); locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT); locationManager.removeUpdates(locationListenerPassivePendingIntent); /** * Instantiate a Location Update Requester class based on the available * platform version. This will be used to request location updates. */ locationUpdateRequester = PlatformSpecificImplementationFactory .getLocationUpdateRequester(this.getApplicationContext(), locationManager); super.onCreate(savedInstanceState); }
From source file:com.airbop.library.simple.CommonUtilities.java
/** * Simple helper that gets the location criteria that we want. * @return//from w w w .ja v a 2 s . c om */ public static Criteria getCriteria() { if (true) { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); return criteria; } return null; }
From source file:com.cloudbees.gasp.activity.GaspLocationsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_locations); GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); LocationManager locationManager;//from www . java 2s . c o m String svcName = Context.LOCATION_SERVICE; locationManager = (LocationManager) getSystemService(svcName); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); Log.i(TAG, "CURRENT LOCATION"); Log.i(TAG, "Latitude = " + location.getLatitude()); Log.i(TAG, "Longitude = " + location.getLongitude()); if (location != null) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); if (!Geocoder.isPresent()) Log.i(TAG, "No geocoder available"); else { try { List<Address> addresses = gc.getFromLocation(latitude, longitude, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); for (int i = 0; i < address.getMaxAddressLineIndex(); i++) sb.append(address.getAddressLine(i)).append(" "); sb.append(address.getLocality()).append(""); sb.append(address.getPostalCode()).append(" "); sb.append(address.getCountryName()); } Log.i(TAG, "Address: " + sb.toString()); } catch (IOException e) { Log.d(TAG, "IOException getting address from geocoder", e); } } } map.setMyLocationEnabled(true); LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder().target(myLocation).zoom(16).bearing(0).tilt(0) .build(); map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); new LocationMapper().execute(); }
From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java
/********************************* * // www.j ava 2 s . c om * 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.android.transmart.PlaceActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate the layout setContentView(R.layout.nearby);/*from w w w. j a va 2 s .com*/ // Get a handle to the Fragments placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(R.id.list_fragment); checkinFragment = (CheckinFragment) getSupportFragmentManager().findFragmentById(R.id.checkin_fragment); // Get references to the managers packageManager = getPackageManager(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Get a reference to the Shared Preferences and a Shared Preference Editor. prefs = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); prefsEditor = prefs.edit(); // Instantiate a SharedPreferenceSaver class based on the available platform version. // This will be used to save shared preferences sharedPreferenceSaver = PlatformSpecific.getSharedPreferenceSaver(this); // Save that we've been run once. prefsEditor.putBoolean(LocationConstants.SP_KEY_RUN_ONCE, true); sharedPreferenceSaver.savePreferences(prefsEditor, false); // Specify the Criteria to use when requesting location updates while the application is Active criteria = new Criteria(); if (LocationConstants.USE_GPS_WHEN_ACTIVITY_VISIBLE) criteria.setAccuracy(Criteria.ACCURACY_FINE); else criteria.setPowerRequirement(Criteria.POWER_LOW); // Setup the location update Pending Intents Intent activeIntent = new Intent(this, LocationChangedReceiver.class); locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent passiveIntent = new Intent(this, PassiveLocReceiver.class); locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Instantiate a LastLocationFinder class. // This will be used to find the last known location when the application starts. lastLocationFinder = PlatformSpecific.getLastLocationFinder(this); lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener); // Instantiate a Location Update Requester class based on the available platform version. // This will be used to request location updates. locationUpdateRequester = PlatformSpecific.getLocationUpdateRequester(locationManager); // Create an Intent Filter to listen for checkins newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class); newCheckinFilter = new IntentFilter(LocationConstants.NEW_CHECKIN_ACTION); // Check to see if an Place ID has been specified in the launch Intent. // If so, we should display the details for the specified venue. if (getIntent().hasExtra(LocationConstants.EXTRA_KEY_ID)) { Intent intent = getIntent(); String key = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID); if (key != null) { selectDetail(null, key); // Remove the ID from the Intent (so that a resume doesn't reselect). intent.removeExtra(LocationConstants.EXTRA_KEY_ID); setIntent(intent); } } }