Search in sources :

Example 26 with LocationProvider

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;
}
Also used : LocationProvider(android.location.LocationProvider) Criteria(android.location.Criteria)

Example 27 with LocationProvider

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));
    }
}
Also used : LocationManager(android.location.LocationManager) LocationProvider(android.location.LocationProvider) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) IOException(java.io.IOException)

Aggregations

LocationProvider (android.location.LocationProvider)27 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 Criteria (android.location.Criteria)1 Location (android.location.Location)1 LocationManager (android.location.LocationManager)1 Looper (android.os.Looper)1 IOException (java.io.IOException)1