Search in sources :

Example 86 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 87 with LocationManager

use of android.location.LocationManager in project AndEngine by nicolasgramlich.

the class Engine method disableLocationSensor.

public void disableLocationSensor(final Context pContext) {
    final LocationManager locationManager = (LocationManager) pContext.getSystemService(Context.LOCATION_SERVICE);
    locationManager.removeUpdates(this);
}
Also used : LocationManager(android.location.LocationManager)

Example 88 with LocationManager

use of android.location.LocationManager in project android_frameworks_base by ParanoidAndroid.

the class TrackerService method initLocationListeners.

private synchronized void initLocationListeners() {
    mTrackerData = new TrackerDataHelper(this);
    LocationManager lm = getLocationManager();
    mTrackedProviders = getTrackedProviders();
    List<String> locationProviders = lm.getAllProviders();
    mListeners = new ArrayList<LocationTrackingListener>(locationProviders.size());
    long minUpdateTime = getLocationUpdateTime();
    float minDistance = getLocationMinDistance();
    for (String providerName : locationProviders) {
        if (mTrackedProviders.contains(providerName)) {
            Log.d(LOG_TAG, "Adding location listener for provider " + providerName);
            if (doDebugLogging()) {
                mTrackerData.writeEntry("init", String.format("start listening to %s : %d ms; %f meters", providerName, minUpdateTime, minDistance));
            }
            LocationTrackingListener listener = new LocationTrackingListener();
            lm.requestLocationUpdates(providerName, minUpdateTime, minDistance, listener);
            mListeners.add(listener);
        }
    }
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (doDebugLogging()) {
        // register for cell location updates
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
        // Register for Network (Wifi or Mobile) updates
        mNetwork = new NetworkStateBroadcastReceiver();
        IntentFilter mIntentFilter;
        mIntentFilter = new IntentFilter();
        mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
        mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        mIntentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        Log.d(LOG_TAG, "registering receiver");
        registerReceiver(mNetwork, mIntentFilter);
    }
    if (trackSignalStrength()) {
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }
    // register for preference changes, so we can restart listeners on
    // pref changes
    mPrefListener = new PreferenceListener();
    getPreferences().registerOnSharedPreferenceChangeListener(mPrefListener);
}
Also used : LocationManager(android.location.LocationManager) IntentFilter(android.content.IntentFilter) TrackerDataHelper(com.android.locationtracker.data.TrackerDataHelper)

Example 89 with LocationManager

use of android.location.LocationManager in project android_frameworks_base by ParanoidAndroid.

the class NetInitiatedActivity method sendUserResponse.

// Respond to NI Handler under GpsLocationProvider, 1 = accept, 2 = deny
private void sendUserResponse(int response) {
    if (DEBUG)
        Log.d(TAG, "sendUserResponse, response: " + response);
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    locationManager.sendNiResponse(notificationId, response);
}
Also used : LocationManager(android.location.LocationManager)

Example 90 with LocationManager

use of android.location.LocationManager in project android_frameworks_base by ParanoidAndroid.

the class ExternalSharedPermsTest method testRunLocationAndBluetooth.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunLocationAndBluetooth() {
    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) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Aggregations

LocationManager (android.location.LocationManager)151 Location (android.location.Location)51 Bundle (android.os.Bundle)33 LocationListener (android.location.LocationListener)29 Criteria (android.location.Criteria)21 Intent (android.content.Intent)20 BluetoothAdapter (android.bluetooth.BluetoothAdapter)15 View (android.view.View)10 SuppressLint (android.annotation.SuppressLint)9 IOException (java.io.IOException)9 ConnectivityManager (android.net.ConnectivityManager)7 WifiManager (android.net.wifi.WifiManager)7 TextView (android.widget.TextView)7 DialogInterface (android.content.DialogInterface)6 IntentFilter (android.content.IntentFilter)6 SharedPreferences (android.content.SharedPreferences)6 PendingIntent (android.app.PendingIntent)5 NetworkInfo (android.net.NetworkInfo)5 TelephonyManager (android.telephony.TelephonyManager)5 TrackerDataHelper (com.android.locationtracker.data.TrackerDataHelper)5