Search in sources :

Example 16 with LocationManager

use of android.location.LocationManager in project platform_frameworks_base by android.

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 17 with LocationManager

use of android.location.LocationManager in project platform_frameworks_base by android.

the class NetInitiatedActivity method sendUserResponse.

// Respond to NI Handler under GnssLocationProvider, 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 18 with LocationManager

use of android.location.LocationManager in project carat by amplab.

the class Sampler method requestLocationUpdates.

private void requestLocationUpdates() {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    lm.removeUpdates(this);
    List<String> providers = SamplingLibrary.getEnabledLocationProviders(context);
    if (providers != null) {
        for (String provider : providers) {
            lm.requestLocationUpdates(provider, Constants.FRESHNESS_TIMEOUT, 0, this);
        // Log.v(TAG, "Location updates requested for " + provider);
        }
    }
}
Also used : LocationManager(android.location.LocationManager)

Example 19 with LocationManager

use of android.location.LocationManager in project carat by amplab.

the class SamplingLibrary method getBestProvider.

public static String getBestProvider(Context context) {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    Criteria c = new Criteria();
    c.setAccuracy(Criteria.ACCURACY_COARSE);
    c.setPowerRequirement(Criteria.POWER_LOW);
    String provider = lm.getBestProvider(c, true);
    return provider;
}
Also used : LocationManager(android.location.LocationManager) Criteria(android.location.Criteria)

Example 20 with LocationManager

use of android.location.LocationManager in project carat by amplab.

the class SamplingLibrary method getLastKnownLocation.

private static Location getLastKnownLocation(Context context, String provider) {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    Location l = lm.getLastKnownLocation(provider);
    return l;
}
Also used : LocationManager(android.location.LocationManager) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) Location(android.location.Location) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation)

Aggregations

LocationManager (android.location.LocationManager)70 Location (android.location.Location)31 Bundle (android.os.Bundle)23 LocationListener (android.location.LocationListener)22 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 Criteria (android.location.Criteria)8 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 FacebookException (com.facebook.FacebookException)2 ArrayList (java.util.ArrayList)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 ActivityManager (android.app.ActivityManager)1 AlarmManager (android.app.AlarmManager)1 KeyguardManager (android.app.KeyguardManager)1 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1