use of android.location.LocationProvider in project CodenameOne by codenameone.
the class AndroidLocationManager method findProvider.
private String findProvider(boolean includeNetwork) {
String providerName = null;
Criteria criteria = new Criteria();
criteria.setSpeedRequired(true);
criteria.setAltitudeRequired(true);
LocationProvider provider;
boolean enabled;
if (includeNetwork) {
provider = locationManager.getProvider(LocationManager.NETWORK_PROVIDER);
enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (provider != null && enabled) {
providerName = provider.getName();
} else {
providerName = locationManager.getBestProvider(criteria, true);
}
}
if (providerName == null) {
// If GPS provider, then create and start GPS listener
provider = locationManager.getProvider(LocationManager.GPS_PROVIDER);
enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (provider != null && enabled) {
providerName = provider.getName();
}
}
return providerName;
}
use of android.location.LocationProvider in project wigle-wifi-wardriving by wiglenet.
the class MainActivity method setupLocation.
private void setupLocation() {
final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
try {
// check if there is a gps
final LocationProvider locProvider = locationManager.getProvider(GPS_PROVIDER);
if (locProvider == null && !isFinishing()) {
WiGLEToast.showOverActivity(this, R.string.app_name, getString(R.string.no_gps_device), Toast.LENGTH_LONG);
} else if (!locationManager.isProviderEnabled(GPS_PROVIDER) && !isFinishing()) {
// gps exists, but isn't on
WiGLEToast.showOverActivity(this, R.string.app_name, getString(R.string.turn_on_gps), Toast.LENGTH_LONG);
final Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
try {
startActivity(myIntent);
} catch (Exception ex) {
error("exception trying to start location activity: " + ex, ex);
}
}
} catch (final SecurityException ex) {
info("Security exception in setupLocation: " + ex);
return;
}
if (state.gpsListener == null) {
// force a listener to be created
final SharedPreferences prefs = getSharedPreferences(ListFragment.SHARED_PREFS, 0);
internalHandleScanChange(prefs.getBoolean(ListFragment.PREF_SCAN_RUNNING, true));
}
}
Aggregations