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;
}
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);
}
}
}
use of android.location.LocationManager in project twicalico by moko256.
the class PostActivity method updateLocation.
private void updateLocation() {
LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
disposable.add(new LocationSingleBuilder(Objects.requireNonNull(locationManager)).getSingle().subscribe(it -> {
model.getUpdateStatus().setLocation(new Pair<>(it.getLatitude(), it.getLongitude()));
locationText.setText(getString(R.string.lat_and_lon, it.getLatitude(), it.getLongitude()));
}, this::errorNotify));
}
use of android.location.LocationManager in project Klyph by jonathangerbaud.
the class PlacePickerActivity method onStop.
@Override
protected void onStop() {
super.onStop();
if (locationListener != null) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.removeUpdates(locationListener);
locationListener = null;
}
}
use of android.location.LocationManager in project aware-client by denzilferreira.
the class Aware method complianceStatus.
// public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
// ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
// if (serviceClass.getName().equals(service.service.getClassName())) {
// return true;
// }
// }
// return false;
// }
private static void complianceStatus(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
JSONObject complianceStatus = new JSONObject();
try {
NetworkInfo active = connManager.getActiveNetworkInfo();
if (active != null && active.isConnectedOrConnecting()) {
complianceStatus.put("internet", true);
} else {
complianceStatus.put("internet", false);
}
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifi != null && wifi.isAvailable()) {
complianceStatus.put("wifi", true);
} else {
complianceStatus.put("wifi", false);
}
NetworkInfo bt = connManager.getNetworkInfo(ConnectivityManager.TYPE_BLUETOOTH);
if (bt != null && bt.isAvailable()) {
complianceStatus.put("bt", true);
} else {
complianceStatus.put("bt", false);
}
NetworkInfo network = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (network != null && network.isAvailable()) {
complianceStatus.put("network", true);
} else {
complianceStatus.put("network", false);
}
boolean airplane = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
complianceStatus.put("airplane", airplane);
complianceStatus.put("roaming", telephonyManager.isNetworkRoaming());
complianceStatus.put("location_gps", locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
complianceStatus.put("location_network", locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
Aware.debug(context, complianceStatus.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
Aggregations