Search in sources :

Example 51 with Criteria

use of android.location.Criteria in project apps-android-commons by commons-app.

the class GPSExtractor method registerLocationManager.

/**
     * Registers a LocationManager to listen for current location
     */
protected void registerLocationManager() {
    locationManager = (LocationManager) CommonsApplication.getInstance().getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    String provider = locationManager.getBestProvider(criteria, true);
    myLocationListener = new MyLocationListener();
    try {
        locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener);
        Location location = locationManager.getLastKnownLocation(provider);
        if (location != null) {
            myLocationListener.onLocationChanged(location);
        }
    } catch (IllegalArgumentException e) {
        Timber.e(e, "Illegal argument exception");
    } catch (SecurityException e) {
        Timber.e(e, "Security exception");
    }
}
Also used : Criteria(android.location.Criteria) Location(android.location.Location)

Aggregations

Criteria (android.location.Criteria)51 Location (android.location.Location)19 Test (org.junit.Test)12 LocationManager (android.location.LocationManager)8 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 Bundle (android.os.Bundle)6 Handler (android.os.Handler)6 LocationListener (android.location.LocationListener)5 SuppressLint (android.annotation.SuppressLint)2 FacebookException (com.facebook.FacebookException)2 HashMap (java.util.HashMap)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 EditTextPreference (android.preference.EditTextPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 PreferenceCategory (android.preference.PreferenceCategory)1