Search in sources :

Example 91 with LocationManager

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

the class ExternalSharedPermsDiffKeyTest method testRunBluetoothAndFineLocation.

/** 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 testRunBluetoothAndFineLocation() {
    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();
    }
    fail("this app was signed by a different cert and should crash/fail to run by now");
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Example 92 with LocationManager

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

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

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

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

use of android.location.LocationManager in project QLibrary by DragonsQC.

the class NetStateUtils method isGpsEnabled.

/**
     * 判断GPS是否打开
     *
     * @return GPS是否打开
     */
public static boolean isGpsEnabled(Context context) {
    LocationManager lm = ((LocationManager) context.getApplicationContext().getSystemService(Context.LOCATION_SERVICE));
    List<String> providers = lm.getProviders(true);
    return providers != null && providers.size() > 0;
}
Also used : LocationManager(android.location.LocationManager)

Example 95 with LocationManager

use of android.location.LocationManager in project XobotOS by xamarin.

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)

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