use of android.location.LocationManager 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.LocationManager in project facebook-android-sdk by facebook.
the class PickerActivity method onStop.
@Override
@SuppressLint("MissingPermission")
protected void onStop() {
super.onStop();
if (locationListener != null) {
if (hasLocationPermissions()) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.removeUpdates(locationListener);
}
locationListener = null;
}
}
use of android.location.LocationManager 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.LocationManager in project gdk-compass-sample by googleglass.
the class CompassService method onCreate.
@Override
public void onCreate() {
super.onCreate();
// Even though the text-to-speech engine is only used in response to a menu action, we
// initialize it when the application starts so that we avoid delays that could occur
// if we waited until it was needed to start it up.
mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// Do nothing.
}
});
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mOrientationManager = new OrientationManager(sensorManager, locationManager);
mLandmarks = new Landmarks(this);
}
use of android.location.LocationManager in project carat by amplab.
the class SamplingLibrary method getGpsEnabled.
/* Check whether GPS are enabled */
public static boolean getGpsEnabled(Context context) {
boolean gpsEnabled = false;
LocationManager myLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
gpsEnabled = myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Log.v("GPS", "GPS is :" + gpsEnabled);
return gpsEnabled;
}
Aggregations