List of usage examples for android.location Criteria ACCURACY_FINE
int ACCURACY_FINE
To view the source code for android.location Criteria ACCURACY_FINE.
Click Source Link
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 w w .j ava 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:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java
public void setupLocationUpdates(GpsLocationOverlay gpsLocationOverlay) { //the user may have disabled us from reading location data if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Criteria criteria = new Criteria(); criteria.setSpeedRequired(false); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false);//w w w . j av a 2s . c om String locationProviderName = locationManager.getBestProvider(criteria, true); locationManager.requestLocationUpdates(locationProviderName, 0, 0, gpsLocationOverlay, getMainLooper()); } }
From source file:org.navitproject.navit.NavitVehicle.java
/** * @brief Creates a new {@code NavitVehicle} * * @param context/*from w w w . ja v a 2 s.c o m*/ * @param pcbid The address of the position callback function called when a location update is received * @param scbid The address of the status callback function called when a status update is received * @param fcbid The address of the fix callback function called when a * {@code android.location.GPS_FIX_CHANGE} is received, indicating a change in GPS fix status */ NavitVehicle(Context context, int pcbid, int scbid, int fcbid) { if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission is not granted return; } this.context = context; sLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); preciseLocationListener = new NavitLocationListener(); preciseLocationListener.precise = true; fastLocationListener = new NavitLocationListener(); /* Use 2 LocationProviders, one precise (usually GPS), and one not so precise, but possible faster. The fast provider is disabled when the precise provider gets its first fix. */ // Selection criteria for the precise provider Criteria highCriteria = new Criteria(); highCriteria.setAccuracy(Criteria.ACCURACY_FINE); highCriteria.setAltitudeRequired(true); highCriteria.setBearingRequired(true); highCriteria.setCostAllowed(true); highCriteria.setPowerRequirement(Criteria.POWER_HIGH); // Selection criteria for the fast provider Criteria lowCriteria = new Criteria(); lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE); lowCriteria.setAltitudeRequired(false); lowCriteria.setBearingRequired(false); lowCriteria.setCostAllowed(true); lowCriteria.setPowerRequirement(Criteria.POWER_HIGH); Log.e("NavitVehicle", "Providers " + sLocationManager.getAllProviders()); preciseProvider = sLocationManager.getBestProvider(highCriteria, false); Log.e("NavitVehicle", "Precise Provider " + preciseProvider); fastProvider = sLocationManager.getBestProvider(lowCriteria, false); Log.e("NavitVehicle", "Fast Provider " + fastProvider); vehicle_pcbid = pcbid; vehicle_scbid = scbid; vehicle_fcbid = fcbid; context.registerReceiver(preciseLocationListener, new IntentFilter(GPS_FIX_CHANGE)); sLocationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener); sLocationManager.addGpsStatusListener(preciseLocationListener); /* * Since Android criteria have no way to specify "fast fix", lowCriteria may return the same * provider as highCriteria, even if others are available. In this case, do not register two * listeners for the same provider but pick the fast provider manually. (Usually there will * only be two providers in total, which makes the choice easy.) */ if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0) { List<String> fastProviderList = sLocationManager.getProviders(lowCriteria, false); fastProvider = null; for (String fastCandidate : fastProviderList) { if (preciseProvider.compareTo(fastCandidate) != 0) { fastProvider = fastCandidate; break; } } } if (fastProvider != null) { sLocationManager.requestLocationUpdates(fastProvider, 0, 0, fastLocationListener); } }
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 av a2 s . c om*/ // 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); } } }
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); }/* w ww .ja va 2 s . com*/ 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:com.riverspart.location.ui.PlaceActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate the layout setContentView(R.layout.location_main); // 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(PlacesConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); prefsEditor = prefs.edit();/*from w ww . j a v a 2s . com*/ // Instantiate a SharedPreferenceSaver class based on the available platform version. // This will be used to save shared preferences sharedPreferenceSaver = PlatformSpecificImplementationFactory.getSharedPreferenceSaver(this); // Save that we've been run once. prefsEditor.putBoolean(PlacesConstants.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 (PlacesConstants.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); // 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); // Instantiate a Location Update Requester class based on the available platform version. // This will be used to request location updates. locationUpdateRequester = PlatformSpecificImplementationFactory.getLocationUpdateRequester(locationManager); // Create an Intent Filter to listen for checkins newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class); newCheckinFilter = new IntentFilter(PlacesConstants.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(PlacesConstants.EXTRA_KEY_ID)) { Intent intent = getIntent(); String key = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID); if (key != null) { selectDetail(null, key); // Remove the ID from the Intent (so that a resume doesn't reselect). intent.removeExtra(PlacesConstants.EXTRA_KEY_ID); setIntent(intent); } } }
From source file:com.intel.xdk.geolocation.Geolocation.java
private String getBestProvider(boolean highAccuracy) { Criteria c = new Criteria(); c.setAccuracy(highAccuracy ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE); String provider = locMan.getBestProvider(c, true); //System.out.println("getBestProvider: " + provider); return provider; }
From source file:com.rareventure.android.GpsReader.java
public void turnOn() { synchronized (lock) { // Log.d(GpsTrailerService.TAG,"Turning on gps"); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { GTG.alert(GTGEvent.ERROR_GPS_DISABLED); return; }//from ww w . j a v a 2 s .c o m if (ActivityCompat.checkSelfPermission(this.ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { GTG.alert(GTGEvent.ERROR_GPS_NO_PERMISSION); // Log.d(GpsTrailerService.TAG,"Failed no permission"); return; } if (gpsOn) { // Log.d(GpsTrailerService.TAG,"Gps already on"); return; //already on } gpsOn = true; // Log.d(GpsTrailerService.TAG,"Really turning on"); Criteria criteria = new Criteria(); criteria.setSpeedRequired(false); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false); String providerName = lm.getBestProvider(criteria, true); lm.requestLocationUpdates(providerName, prefs.gpsRecurringTimeMs, 0, locationListener, looper); } }
From source file:net.digitalphantom.app.weatherapp.WeatherActivity.java
private void getWeatherFromCurrentLocation() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, }, GET_WEATHER_FROM_CURRENT_LOCATION); return;// w ww. j av a2 s .co m } // system's LocationManager final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); Criteria locationCriteria = new Criteria(); if (isNetworkEnabled) { locationCriteria.setAccuracy(Criteria.ACCURACY_COARSE); } else if (isGPSEnabled) { locationCriteria.setAccuracy(Criteria.ACCURACY_FINE); } locationManager.requestSingleUpdate(locationCriteria, this, null); }
From source file:tjs.tuneramblr.TuneramblrMobileActivity.java
/** Called when the activity is first created. */ @Override/*from w w w. ja va 2 s.c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // set the current view setContentView(R.layout.main); // retrieve the fragments checkinFragment = new CheckinFragment(); loginFragment = new LoginFragment(); // determine which fragment we want to show UserInfoDS userInfoDs = new UserInfoDS(getApplicationContext()); UserInfo userInfo = null; try { userInfo = userInfoDs.readUserInfo(); } catch (IOException e) { userInfo = null; } Fragment fragment = null; if ((userInfo != null) && (userInfo.getUsername() != null) && (userInfo.getPassword() != null)) { fragment = checkinFragment; } else { fragment = loginFragment; } // add the fragment to the the main layout getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, fragment).commit(); // 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(TuneramblrConstants.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 = PlatformSpecificImplementationFactory.getSharedPreferenceSaver(this); // Save that we've been run once. prefsEditor.putBoolean(TuneramblrConstants.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 (TuneramblrConstants.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); // 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); // Instantiate a Location Update Requester class based on the available // platform version. // This will be used to request location updates. locationUpdateRequester = PlatformSpecificImplementationFactory.getLocationRequester(locationManager); // Create an Intent Filter to listen for checkins newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class); newCheckinFilter = new IntentFilter(TuneramblrConstants.NEW_CHECKIN_ACTION); // check if anything has changed if (getIntent().hasExtra(TuneramblrConstants.EXTRA_KEY_ID)) { // nadda right now } }