Example usage for android.location LocationManager GPS_PROVIDER

List of usage examples for android.location LocationManager GPS_PROVIDER

Introduction

In this page you can find the example usage for android.location LocationManager GPS_PROVIDER.

Prototype

String GPS_PROVIDER

To view the source code for android.location LocationManager GPS_PROVIDER.

Click Source Link

Document

Name of the GPS location provider.

Usage

From source file:com.taw.gotothere.GoToThereActivity.java

/**
 *  Check if the GPS sensor is switched on.
 *  // w  ww.  java2 s .  c  o m
 *  @return true if on, false otherwise
 */
private boolean isGPSOn() {
    LocationManager locationManager = (LocationManager) getSystemService(Service.LOCATION_SERVICE);
    return (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) ? true : false;
}

From source file:com.geotrackin.gpslogger.GpsLoggingService.java

/**
 * This method is called periodically to determine whether the cell tower /
 * gps providers have been enabled, and sets class level variables to those
 * values./*from  w  w w .ja va  2s .  c om*/
 */
private void CheckTowerAndGpsStatus() {
    Session.setTowerEnabled(towerLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
    Session.setGpsEnabled(gpsLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
}

From source file:com.vonglasow.michael.satstat.MapSectionFragment.java

@Override
public void onStart() {
    super.onStart();
    LayerManager layerManager = mapMap.getLayerManager();
    Layers layers = layerManager.getLayers();
    layers.clear();//  w  w  w  . java2 s.co m

    float lat = mainActivity.mSharedPreferences.getFloat(SettingsActivity.KEY_PREF_MAP_LAT, 360.0f);
    float lon = mainActivity.mSharedPreferences.getFloat(SettingsActivity.KEY_PREF_MAP_LON, 360.0f);

    if ((lat < 360.0f) && (lon < 360.0f)) {
        mapMap.getModel().mapViewPosition.setCenter(new LatLong(lat, lon));
    }

    int zoom = mainActivity.mSharedPreferences.getInt(SettingsActivity.KEY_PREF_MAP_ZOOM, 16);
    mapMap.getModel().mapViewPosition.setZoomLevel((byte) zoom);

    /*
      TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache,
      mapMap.getModel().mapViewPosition, false, AndroidGraphicFactory.INSTANCE);
            
      //FIXME: have user select map file
      tileRendererLayer.setMapFile(new File(Environment.getExternalStorageDirectory(), "org.openbmap/maps/germany.map"));
            
      tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);
            
      //tileRendererLayer.setTextScale(1.5f);
      layers.add(tileRendererLayer);
     */

    mapDownloadLayer = new TileDownloadLayer(mapTileCache, mapMap.getModel().mapViewPosition, onlineTileSource,
            AndroidGraphicFactory.INSTANCE);
    layers.add(mapDownloadLayer);

    //parse list of location providers
    onLocationProvidersChanged(mainActivity.mSharedPreferences.getStringSet(SettingsActivity.KEY_PREF_LOC_PROV,
            new HashSet<String>(Arrays
                    .asList(new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER }))));
}

From source file:com.mendhak.gpslogger.GpsLoggingService.java

/**
 * Starts the location manager. There are two location managers - GPS and
 * Cell Tower. This code determines which manager to request updates from
 * based on user preference and whichever is enabled. If GPS is enabled on
 * the phone, that is used. But if the user has also specified that they
 * prefer cell towers, then cell towers are used. If neither is enabled,
 * then nothing is requested.//from w  w w  .jav  a  2s  .c o m
 */
@SuppressWarnings("ResourceType")
private void startGpsManager() {

    //If the user has been still for more than the minimum seconds
    if (userHasBeenStillForTooLong()) {
        LOG.info("No movement detected in the past interval, will not log");
        setAlarmForNextPoint();
        return;
    }

    if (gpsLocationListener == null) {
        gpsLocationListener = new GeneralLocationListener(this, "GPS");
    }

    if (towerLocationListener == null) {
        towerLocationListener = new GeneralLocationListener(this, "CELL");
    }

    gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    checkTowerAndGpsStatus();

    if (Session.isGpsEnabled()
            && preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) {
        LOG.info("Requesting GPS location updates");
        // gps satellite based
        gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener);
        gpsLocationManager.addGpsStatusListener(gpsLocationListener);
        gpsLocationManager.addNmeaListener(gpsLocationListener);

        Session.setUsingGps(true);
        startAbsoluteTimer();
    }

    if (Session.isTowerEnabled()
            && (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER)
                    || !Session.isGpsEnabled())) {
        LOG.info("Requesting cell and wifi location updates");
        Session.setUsingGps(false);
        // Cell tower and wifi based
        towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0,
                towerLocationListener);

        startAbsoluteTimer();
    }

    if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) {
        LOG.error("No provider available!");
        Session.setUsingGps(false);
        LOG.error(getString(R.string.gpsprovider_unavailable));
        stopLogging();
        setLocationServiceUnavailable();
        return;
    }

    EventBus.getDefault().post(new ServiceEvents.WaitingForLocation(true));
    Session.setWaitingForLocation(true);
}

From source file:in.codehex.arrow.MainActivity.java

/**
 * @param context context of the MainActivity class
 * @return true if GPS is enabled else false
 *///from   w ww .  ja va  2 s  . c om
private boolean isGPSEnabled(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:com.crearo.gpslogger.GpsLoggingService.java

/**
 * Starts the location manager. There are two location managers - GPS and
 * Cell Tower. This code determines which manager to request updates from
 * based on user preference and whichever is enabled. If GPS is enabled on
 * the phone, that is used. But if the user has also specified that they
 * prefer cell towers, then cell towers are used. If neither is enabled,
 * then nothing is requested.// w ww  .j  a va  2 s.c o m
 */
private void startGpsManager() {

    //If the user has been still for more than the minimum seconds
    if (userHasBeenStillForTooLong()) {
        LOG.info("No movement detected in the past interval, will not log");
        setAlarmForNextPoint();
        return;
    }

    if (gpsLocationListener == null) {
        gpsLocationListener = new GeneralLocationListener(this, "GPS");
    }

    if (towerLocationListener == null) {
        towerLocationListener = new GeneralLocationListener(this, "CELL");
    }

    gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    checkTowerAndGpsStatus();

    if (Session.isGpsEnabled()
            && preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) {
        LOG.info("Requesting GPS location updates");
        // gps satellite based
        gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener);
        gpsLocationManager.addGpsStatusListener(gpsLocationListener);
        gpsLocationManager.addNmeaListener(gpsLocationListener);

        Session.setUsingGps(true);
        startAbsoluteTimer();
    }

    if (Session.isTowerEnabled()
            && (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER)
                    || !Session.isGpsEnabled())) {
        LOG.info("Requesting cell and wifi location updates");
        Session.setUsingGps(false);
        // Cell tower and wifi based
        towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0,
                towerLocationListener);

        startAbsoluteTimer();
    }

    if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) {
        LOG.error("No provider available!");
        Session.setUsingGps(false);
        LOG.error(getString(R.string.gpsprovider_unavailable));
        stopLogging();
        setLocationServiceUnavailable();
        return;
    }

    EventBus.getDefault().post(new ServiceEvents.WaitingForLocation(true));
    Session.setWaitingForLocation(true);
}

From source file:com.vonglasow.michael.satstat.ui.MainActivity.java

/**
 * Called when a new location is found by a registered location provider.
 * Stores the location and updates GPS display and map view.
 *//*ww w .java2s  .  com*/
public void onLocationChanged(Location location) {
    // update map view
    if (mapSectionFragment != null) {
        mapSectionFragment.onLocationChanged(location);
    }

    // update GPS view
    if ((location.getProvider().equals(LocationManager.GPS_PROVIDER)) && (gpsSectionFragment != null)) {
        gpsSectionFragment.onLocationChanged(location);
    }
}

From source file:eu.basicairdata.graziano.gpslogger.GPSApplication.java

public void setGPSLocationUpdates(boolean state) {
    // Request permissions = https://developer.android.com/training/permissions/requesting.html

    if (!state && !getRecording() && isGPSLocationUpdatesActive && (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
        GPSStatus = GPS_SEARCHING;/*from w  w  w.j  a va2  s.  c om*/
        mlocManager.removeGpsStatusListener(this);
        mlocManager.removeUpdates(this);
        isGPSLocationUpdatesActive = false;
    }
    if (state && !isGPSLocationUpdatesActive && (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
        mlocManager.addGpsStatusListener(this);
        mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, prefGPSupdatefrequency, 0, this); // Requires Location update
        isGPSLocationUpdatesActive = true;
        StabilizingSamples = (int) Math.ceil(STABILIZERVALUE / prefGPSupdatefrequency);
    }
}

From source file:com.klaasnotfound.locationassistant.LocationAssistant.java

private void checkProviders() {
    // Do it the old fashioned way
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (gps || network)
        return;/*from  ww  w .j a v a  2s. c  o  m*/
    if (listener != null)
        listener.onFallBackToSystemSettings(onGoToLocationSettingsFromView, onGoToLocationSettingsFromDialog);
    else if (!quiet)
        Log.e(getClass().getSimpleName(),
                "Location providers need to be enabled, but no listener is "
                        + "registered! Specify a valid listener when constructing " + getClass().getSimpleName()
                        + " or register it explicitly with register().");
}

From source file:eu.geopaparazzi.library.gps.GpsService.java

/**
 * Checks if the GPS is switched on./* ww  w  . j a  va  2  s  .  com*/
 * <p/>
 * <p>Does not say if the GPS is supplying valid data.</p>
 *
 * @return <code>true</code> if the GPS is switched on.
 */
private boolean isGpsOn() {
    if (locationManager == null) {
        return false;
    }
    boolean gpsIsEnabled;
    if (useNetworkPositions) {
        gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    } else {
        gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }
    logABS("Gps is enabled: " + gpsIsEnabled);
    return gpsIsEnabled;
}