use of android.location.Criteria in project android_frameworks_base by crdroidandroid.
the class LocationManagerTest method testGetBestProviderEmptyCriteria.
public void testGetBestProviderEmptyCriteria() {
String p = manager.getBestProvider(new Criteria(), true);
assertNotNull(p);
}
use of android.location.Criteria in project android_frameworks_base by crdroidandroid.
the class FusedPrintersProvider method onStartLoading.
@Override
protected void onStartLoading() {
if (DEBUG) {
Log.i(LOG_TAG, "onStartLoading() " + FusedPrintersProvider.this.hashCode());
}
if (getContext().checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationManager.requestLocationUpdates(LocationRequest.create().setQuality(LocationRequest.POWER_LOW).setInterval(LOCATION_UPDATE_MS), this, Looper.getMainLooper());
Location lastLocation = mLocationManager.getLastLocation();
if (lastLocation != null) {
onLocationChanged(lastLocation);
}
// Jumpstart location with a single forced update
Criteria oneTimeCriteria = new Criteria();
oneTimeCriteria.setAccuracy(Criteria.ACCURACY_FINE);
mLocationManager.requestSingleUpdate(oneTimeCriteria, this, Looper.getMainLooper());
}
// The contract is that if we already have a valid,
// result the we have to deliver it immediately.
(new Handler(Looper.getMainLooper())).post(new Runnable() {
@Override
public void run() {
deliverResult(new ArrayList<>(mPrinters));
}
});
// Always load the data to ensure discovery period is
// started and to make sure obsolete printers are updated.
onForceLoad();
}
use of android.location.Criteria in project glasquare by davidvavra.
the class LocationUtils method getRecentLocation.
public static void getRecentLocation(final LocationListener listener) {
Location last = LocationUtils.getLastLocation();
if (last == null || LocationUtils.getAgeInSeconds(last.getTime()) > 60) {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_MEDIUM);
final LocationManager locationManager = (LocationManager) App.get().getSystemService(Context.LOCATION_SERVICE);
List<String> providers = locationManager.getProviders(criteria, true);
if (providers.size() == 0) {
listener.onLocationFailed();
return;
}
locationSuccess = false;
final android.location.LocationListener locationListener = new android.location.LocationListener() {
@Override
public void onLocationChanged(Location location) {
locationSuccess = true;
locationManager.removeUpdates(this);
listener.onLocationAcquired(location);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
for (String provider : providers) {
locationManager.requestLocationUpdates(provider, 1000, 5, locationListener);
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!locationSuccess) {
locationManager.removeUpdates(locationListener);
listener.onLocationFailed();
}
}
}, 5000);
} else {
listener.onLocationAcquired(last);
}
}
use of android.location.Criteria in project facebook-android-sdk by facebook.
the class PickerActivity method onStart.
@Override
@SuppressLint("MissingPermission")
protected void onStart() {
super.onStart();
if (FRIEND_PICKER.equals(getIntent().getData())) {
try {
friendPickerFragment.loadData(false);
} catch (Exception ex) {
onError(ex);
}
} else if (PLACE_PICKER.equals(getIntent().getData())) {
try {
Location location = null;
Criteria criteria = new Criteria();
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String bestProvider = locationManager.getBestProvider(criteria, false);
if (bestProvider != null && checkForLocationPermissionsAndRequest()) {
location = locationManager.getLastKnownLocation(bestProvider);
if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) {
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
boolean updateLocation = true;
Location prevLocation = placePickerFragment.getLocation();
if (prevLocation != null) {
updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD;
}
if (updateLocation) {
placePickerFragment.setLocation(location);
placePickerFragment.loadData(true);
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
};
locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD, locationListener, Looper.getMainLooper());
}
}
if (location != null) {
placePickerFragment.setLocation(location);
placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
placePickerFragment.setSearchText(SEARCH_TEXT);
placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
placePickerFragment.loadData(false);
}
} catch (Exception ex) {
onError(ex);
}
}
}
use of android.location.Criteria in project Klyph by jonathangerbaud.
the class PlacePickerActivity method onStart.
@Override
protected void onStart() {
super.onStart();
try {
Location location = null;
// Instantiate the default criteria for a location provider
Criteria criteria = new Criteria();
// Get a location manager from the system services
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Get the location provider that best matches the criteria
String bestProvider = locationManager.getBestProvider(criteria, false);
if (bestProvider != null) {
// Get the user's last known location
location = locationManager.getLastKnownLocation(bestProvider);
if (locationListener == null) {
// Set up a location listener if one is not already set
// up
// and the selected provider is enabled
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
// On location updates, compare the current
// location to the desired location set in the
// place picker
float distance = location.distanceTo(placePickerFragment.getLocation());
if (distance >= LOCATION_CHANGE_THRESHOLD) {
placePickerFragment.setLocation(location);
placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
placePickerFragment.setSearchText(SEARCH_TEXT);
placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
placePickerFragment.loadData(true);
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, LOCATION_CHANGE_THRESHOLD, locationListener);
}
}
if (location == null) {
// Todo : set default location the last saved location
location = SAN_FRANCISCO_LOCATION;
}
if (location != null) {
// Configure the place picker: search center, radius,
// query, and maximum results.
placePickerFragment.setLocation(location);
placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
placePickerFragment.setSearchText(SEARCH_TEXT);
placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
// Start the API call
placePickerFragment.loadData(true);
}
/*
* else { // If no location found, show an error
* onError(getResources().getString(R.string.no_location_error),
* true); }
*/
} catch (Exception ex) {
onError(ex);
}
}
Aggregations