Search in sources :

Example 41 with LocationManager

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);
        }
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Criteria(android.location.Criteria) FacebookException(com.facebook.FacebookException) Location(android.location.Location) SuppressLint(android.annotation.SuppressLint)

Example 42 with LocationManager

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;
    }
}
Also used : LocationManager(android.location.LocationManager) SuppressLint(android.annotation.SuppressLint)

Example 43 with LocationManager

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);
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) Handler(android.os.Handler) Criteria(android.location.Criteria) Location(android.location.Location)

Example 44 with LocationManager

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);
}
Also used : LocationManager(android.location.LocationManager) SensorManager(android.hardware.SensorManager) Landmarks(com.google.android.glass.sample.compass.model.Landmarks) TextToSpeech(android.speech.tts.TextToSpeech)

Example 45 with LocationManager

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;
}
Also used : LocationManager(android.location.LocationManager)

Aggregations

LocationManager (android.location.LocationManager)74 Location (android.location.Location)33 Bundle (android.os.Bundle)24 LocationListener (android.location.LocationListener)23 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 Criteria (android.location.Criteria)9 IntentFilter (android.content.IntentFilter)5 TrackerDataHelper (com.android.locationtracker.data.TrackerDataHelper)5 IOException (java.io.IOException)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 SensorManager (android.hardware.SensorManager)2 ConnectivityManager (android.net.ConnectivityManager)2 TelephonyManager (android.telephony.TelephonyManager)2 FacebookException (com.facebook.FacebookException)2 LatLng (com.google.android.gms.maps.model.LatLng)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 ActivityManager (android.app.ActivityManager)1 AlarmManager (android.app.AlarmManager)1 KeyguardManager (android.app.KeyguardManager)1