Example usage for android.location LocationProvider OUT_OF_SERVICE

List of usage examples for android.location LocationProvider OUT_OF_SERVICE

Introduction

In this page you can find the example usage for android.location LocationProvider OUT_OF_SERVICE.

Prototype

int OUT_OF_SERVICE

To view the source code for android.location LocationProvider OUT_OF_SERVICE.

Click Source Link

Usage

From source file:com.moodmap.HomeActivity.java

private void registerLocationListeners() {
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if (mLocationListener_Fine == null) {
        mLocationListener_Fine = new LocationListener() {
            // LocationListener
            @Override//  w w w.  j  a  v  a  2  s . co m
            public void onLocationChanged(Location location) {

                float currentLocationAccuracy = location.getAccuracy();

                myLocationFixCnt_Fine++;
                if ((myLocationFixCnt_Fine >= Constants.kMaxGpsFixCnt)
                        || ((location.hasAccuracy()) && (currentLocationAccuracy <= 60.0))) // tighter,
                                                                                                                                                   // slower
                                                                                                                                                   // location
                {
                    // stop the fine location service
                    mLocationManager.removeUpdates(this);

                    // also stop the coarse location updates, if for some
                    // reason it has not resolved yet
                    if (mLocationListener_Coarse != null) {
                        mLocationManager.removeUpdates(mLocationListener_Coarse);
                    }
                }
                updateMyLocation(location);
            }

            @Override
            public void onProviderDisabled(String provider) {
                Log.v(Constants.LOGTAG, "Fine Provider Disabled: " + provider);
            }

            @Override
            public void onProviderEnabled(String provider) {
                Log.v(Constants.LOGTAG, "Fine Provider Enabled: " + provider);
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                myStatusChangeCnt_Fine++;
                if ((status == LocationProvider.OUT_OF_SERVICE))
                // not sure if needed (myStatusChangeCnt_Fine >=
                // Constants.kMaxGpsFixCnt))
                {
                    // if cannot resolve the location, do not leave the gps
                    // running
                    mLocationManager.removeUpdates(mLocationListener_Fine);
                }
                Log.v(Constants.LOGTAG, "Fine Provider Status Change (OVER): " + provider + " status:" + status
                        + " myStatusChangeCnt_Fine:" + myStatusChangeCnt_Fine);

                // LocationProvider.OUT_OF_SERVICE
            }
        };
    }

    if (mLocationListener_Coarse == null) {
        mLocationListener_Coarse = new LocationListener() {
            // LocationListener
            @Override
            public void onLocationChanged(Location location) {

                float currentLocationAccuracy = location.getAccuracy();

                myLocationFixCnt_Coarse++;
                if ((myLocationFixCnt_Coarse >= Constants.kMaxGpsFixCnt)
                        || ((location.hasAccuracy()) && (currentLocationAccuracy <= 1000.0))) // quick,
                                                                                                                                                       // rough
                                                                                                                                                       // location
                {
                    // stop the coarse location service
                    mLocationManager.removeUpdates(this);
                }
                updateMyLocation(location);
            }

            @Override
            public void onProviderDisabled(String provider) {
                Log.v(Constants.LOGTAG, "Provider Disabled: " + provider);
            }

            @Override
            public void onProviderEnabled(String provider) {
                Log.v(Constants.LOGTAG, "Provider Enabled: " + provider);
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                Log.v(Constants.LOGTAG, "Provider Status Change: " + provider + " status:" + status);
                // LocationProvider.OUT_OF_SERVICE
            }
        };
    }

    // still in registerLocationListeners
    //
    String provider = null;
    Criteria crta = new Criteria();
    crta.setAccuracy(Criteria.ACCURACY_FINE);
    crta.setAltitudeRequired(false);
    crta.setBearingRequired(false);
    crta.setCostAllowed(false); // Indicates whether the provider is allowed
                                // to incur monetary cost.
                                // crta.setPowerRequirement(Criteria.POWER_MEDIUM); // POWER_LOW);
    provider = mLocationManager.getBestProvider(crta, true);
    // provider = LocationManager.NETWORK_PROVIDER;

    // get the last, possibly very wrong location
    currentLocation = mLocationManager.getLastKnownLocation(provider);
    // updateMyLocation(location);

    // minTime (2nd) the minimum time interval for notifications, in
    // milliseconds. This field is only used as a hint to conserve power,
    // and actual time between location updates may be greater or lesser
    // than this value.
    // minDistance (3rd)the minimum distance interval for notifications, in
    // meters
    // should be ~ 10000, 100
    // mLocationManager.requestLocationUpdates(provider, 3000, 50,
    // mLocationListener_Fine);
    mLocationManager.requestLocationUpdates(provider, 3000, 0, mLocationListener_Fine);

    // Add second quick location provider
    Criteria coarse = new Criteria();
    coarse.setAccuracy(Criteria.ACCURACY_COARSE);
    coarse.setAltitudeRequired(false);
    coarse.setBearingRequired(false);
    // coarse.setCostAllowed(false);
    // crta.setPowerRequirement(Criteria.POWER_MEDIUM); // POWER_LOW);
    String coarseProvider = mLocationManager.getBestProvider(coarse, true);
    if ((provider != null) && (!provider.contentEquals(coarseProvider))) {
        // only add coarse location resolution if DIFFERENT than the fine
        // location provider
        mLocationManager.requestLocationUpdates(coarseProvider, 1000, 1000, mLocationListener_Coarse);
    }
}

From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java

@Override
public final void onStatusChanged(final String provider, final int status, final Bundle extras) {
    String statusString = "Unknown";
    if (status == LocationProvider.AVAILABLE) {
        statusString = "AVAILABLE";
    } else if (status == LocationProvider.OUT_OF_SERVICE) {
        statusString = "OUT OF SERVICE";
    } else if (status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
        statusString = "TEMP UNAVAILABLE";
    }/*  w ww. j a  va  2 s  . c  om*/
    toast("LocationProvider: " + statusString);
}

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

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // This is called when the GPS status changes
    switch (status) {
    case LocationProvider.OUT_OF_SERVICE:
        //Log.w("myApp", "[#] GPSApplication.java - GPS Out of Service");
        gpsunavailablehandler.removeCallbacks(unavailr); // Cancel the previous unavail countdown handler
        GPSStatus = GPS_OUTOFSERVICE;/*from   w ww  .j  av  a 2  s .  c o m*/
        EventBus.getDefault().post(EventBusMSG.UPDATE_FIX);
        //Toast.makeText( getApplicationContext(), "GPS Out of Service", Toast.LENGTH_SHORT).show();
        break;
    case LocationProvider.TEMPORARILY_UNAVAILABLE:
        //Log.w("myApp", "[#] GPSApplication.java - GPS Temporarily Unavailable");
        gpsunavailablehandler.removeCallbacks(unavailr); // Cancel the previous unavail countdown handler
        GPSStatus = GPS_TEMPORARYUNAVAILABLE;
        EventBus.getDefault().post(EventBusMSG.UPDATE_FIX);
        //Toast.makeText( getApplicationContext(), "GPS Temporarily Unavailable", Toast.LENGTH_SHORT).show();
        break;
    case LocationProvider.AVAILABLE:
        gpsunavailablehandler.removeCallbacks(unavailr); // Cancel the previous unavail countdown handler
        //Log.w("myApp", "[#] GPSApplication.java - GPS Available: " + _NumberOfSatellites + " satellites");
        break;
    }
}

From source file:com.androzic.location.LocationService.java

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (LocationManager.GPS_PROVIDER.equals(provider)) {
        switch (status) {
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
        case LocationProvider.OUT_OF_SERVICE:
            tearTrack();//from  w w  w .j a  v  a2 s. co m
            updateNotification();
            break;
        }
    }
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    switch (status) {
    case LocationProvider.AVAILABLE:

        break;//w w  w . j  av  a2  s . c  o  m
    case LocationProvider.OUT_OF_SERVICE:
        break;
    case LocationProvider.TEMPORARILY_UNAVAILABLE:
        break;
    }
}