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");
}
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) {
}
});
}
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);
}
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;
}
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);
}
Aggregations