Search in sources :

Example 36 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by DirtyUnicorns.

the class ExternalSharedPermsFLTest method testRunFineLocation.

/** The use of location manager below is simply to simulate an app that
     *  tries to use it, so we can verify whether permissions are granted and accessible.
     * */
public void testRunFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 37 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by AOSPA.

the class LocationBasedCountryDetector method stop.

/**
     * Stop the current query without notifying the listener.
     */
@Override
public synchronized void stop() {
    if (mLocationListeners != null) {
        for (LocationListener listener : mLocationListeners) {
            unregisterListener(listener);
        }
        mLocationListeners = null;
    }
    if (mTimer != null) {
        mTimer.cancel();
        mTimer = null;
    }
}
Also used : LocationListener(android.location.LocationListener)

Example 38 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by AOSPA.

the class ExternalSharedPermsFLTest method testRunFineLocation.

/** The use of location manager below is simply to simulate an app that
     *  tries to use it, so we can verify whether permissions are granted and accessible.
     * */
public void testRunFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 39 with LocationListener

use of android.location.LocationListener in project robolectric by robolectric.

the class ShadowLocationManager method setProviderEnabled.

public void setProviderEnabled(String provider, boolean isEnabled, List<Criteria> criteria) {
    LocationProviderEntry providerEntry = providersEnabled.get(provider);
    if (providerEntry == null) {
        providerEntry = new LocationProviderEntry();
    }
    providerEntry.enabled = isEnabled;
    providerEntry.criteria = criteria;
    providersEnabled.put(provider, providerEntry);
    List<LocationListener> locationUpdateListeners = new ArrayList<>(getRequestLocationUpdateListeners());
    for (LocationListener locationUpdateListener : locationUpdateListeners) {
        if (isEnabled) {
            locationUpdateListener.onProviderEnabled(provider);
        } else {
            locationUpdateListener.onProviderDisabled(provider);
        }
    }
    // Send intent to notify about provider status
    final Intent intent = new Intent();
    intent.putExtra(LocationManager.KEY_PROVIDER_ENABLED, isEnabled);
    ShadowApplication.getInstance().sendBroadcast(intent);
    Set<PendingIntent> requestLocationUdpatePendingIntentSet = requestLocationUdpateCriteriaPendingIntents.keySet();
    for (PendingIntent requestLocationUdpatePendingIntent : requestLocationUdpatePendingIntentSet) {
        try {
            requestLocationUdpatePendingIntent.send();
        } catch (CanceledException e) {
            requestLocationUdpateCriteriaPendingIntents.remove(requestLocationUdpatePendingIntent);
        }
    }
    // if this provider gets disabled and it was the best active provider, then it's not anymore
    if (provider.equals(bestEnabledProvider) && !isEnabled) {
        bestEnabledProvider = null;
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) LocationListener(android.location.LocationListener) ArrayList(java.util.ArrayList) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 40 with LocationListener

use of android.location.LocationListener in project android_frameworks_base by crdroidandroid.

the class LocationBasedCountryDetector method stop.

/**
     * Stop the current query without notifying the listener.
     */
@Override
public synchronized void stop() {
    if (mLocationListeners != null) {
        for (LocationListener listener : mLocationListeners) {
            unregisterListener(listener);
        }
        mLocationListeners = null;
    }
    if (mTimer != null) {
        mTimer.cancel();
        mTimer = null;
    }
}
Also used : LocationListener(android.location.LocationListener)

Aggregations

LocationListener (android.location.LocationListener)43 Location (android.location.Location)36 Bundle (android.os.Bundle)36 LocationManager (android.location.LocationManager)23 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 Criteria (android.location.Criteria)6 Timer (java.util.Timer)6 TimerTask (java.util.TimerTask)6 IOException (java.io.IOException)3 Intent (android.content.Intent)2 Point (com.esri.core.geometry.Point)2 FacebookException (com.facebook.FacebookException)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 CanceledException (android.app.PendingIntent.CanceledException)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 GpsSatellite (android.location.GpsSatellite)1 GpsStatus (android.location.GpsStatus)1