Java Code Examples for android.location.LocationProvider#AVAILABLE

The following examples show how to use android.location.LocationProvider#AVAILABLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectorService.java    From TowerCollector with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // on Android 10 this callback will never be invoked
    String statusString;
    switch (status) {
        case LocationProvider.AVAILABLE:
            statusString = "AVAILABLE";
            break;
        case LocationProvider.OUT_OF_SERVICE:
            statusString = "OUT_OF_SERVICE";
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            statusString = "TEMPORARILY_UNAVAILABLE";
            break;
        default:
            statusString = "UNKNOWN";
            break;
    }
    Timber.tag(INNER_TAG).d("onStatusChanged(): %s", statusString);
}
 
Example 2
Source File: GpsElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // Called when the provider status changes.
    Log.d(TAG, "Provider status changed: " + provider + " status: "
            + status);
    if (status == LocationProvider.AVAILABLE) {
        // Do nothing, we should get a location update soon which will
        // disable the listener.
    } else if (status == LocationProvider.OUT_OF_SERVICE ||
            status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
        getLocationButton.setEnabled(true);
        getLocationButton.setText(
                getString(R.string.gps_element_acquire_unavailable));
        locationManager.removeUpdates(locationListener);
    }
}
 
Example 3
Source File: GPSApplication.java    From GPSLogger with GNU General Public License v3.0 6 votes vote down vote up
@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;
            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;
    }
}
 
Example 4
Source File: Engine.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void onStatusChanged(final String pProvider, final int pStatus, final Bundle pExtras) {
	switch (pStatus) {
		case LocationProvider.AVAILABLE:
			this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.AVAILABLE, pExtras);
			break;
		case LocationProvider.OUT_OF_SERVICE:
			this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.OUT_OF_SERVICE, pExtras);
			break;
		case LocationProvider.TEMPORARILY_UNAVAILABLE:
			this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.TEMPORARILY_UNAVAILABLE, pExtras);
			break;
		default:
			throw new IllegalArgumentException("Unexpected " + LocationProvider.class.getSimpleName() + ": '" + pStatus + "'.");
	}
}
 
Example 5
Source File: LocationUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * provider的在可用、暂时不可用和无服务三个状态直接切换时触发此函数
 *
 * @param provider 提供者
 * @param status   状态
 * @param extras   provider可选包
 */
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (mListener != null) {
        mListener.onStatusChanged(provider, status, extras);
    }
    switch (status) {
        case LocationProvider.AVAILABLE:
            Log.d("LocationUtils", "当前GPS状态为可见状态");
            break;
        case LocationProvider.OUT_OF_SERVICE:
            Log.d("LocationUtils", "当前GPS状态为服务区外状态");
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            Log.d("LocationUtils", "当前GPS状态为暂停服务状态");
            break;
    }
}
 
Example 6
Source File: RxLocationTool.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
/**
 * provider的在可用、暂时不可用和无服务三个状态直接切换时触发此函数
 *
 * @param provider 提供者
 * @param status   状态
 * @param extras   provider可选包
 */
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (mListener != null) {
        mListener.onStatusChanged(provider, status, extras);
    }
    switch (status) {
        case LocationProvider.AVAILABLE:
            Log.d("onStatusChanged", "当前GPS状态为可见状态");
            break;
        case LocationProvider.OUT_OF_SERVICE:
            Log.d("onStatusChanged", "当前GPS状态为服务区外状态");
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            Log.d("onStatusChanged", "当前GPS状态为暂停服务状态");
            break;
    }
}
 
Example 7
Source File: LocationUtils.java    From Android-UtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * provider的在可用、暂时不可用和无服务三个状态直接切换时触发此函数
 *
 * @param provider 提供者
 * @param status   状态
 * @param extras   provider可选包
 */
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (mListener != null) {
        mListener.onStatusChanged(provider, status, extras);
    }
    switch (status) {
        case LocationProvider.AVAILABLE:
            LogUtils.d("onStatusChanged", "当前GPS状态为可见状态");
            break;
        case LocationProvider.OUT_OF_SERVICE:
            LogUtils.d("onStatusChanged", "当前GPS状态为服务区外状态");
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            LogUtils.d("onStatusChanged", "当前GPS状态为暂停服务状态");
            break;
    }
}
 
Example 8
Source File: LocationUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * provider 的在可用、暂时不可用和无服务三个状态直接切换时触发此函数
 * @param provider 提供者
 * @param status   状态
 * @param extras   provider 可选包
 */
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (sListener != null) {
        sListener.onStatusChanged(provider, status, extras);
    }
    switch (status) {
        case LocationProvider.AVAILABLE:
            LogPrintUtils.dTag(TAG, "当前 GPS 状态为可见状态");
            break;
        case LocationProvider.OUT_OF_SERVICE:
            LogPrintUtils.dTag(TAG, "当前 GPS 状态为服务区外状态");
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            LogPrintUtils.dTag(TAG, "当前 GPS 状态为暂停服务状态");
            break;
    }
}
 
Example 9
Source File: GPSListenersMaker.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
public void onStatusChanged(String provider, int status, Bundle extras) {
    switch (status) {
        case LocationProvider.AVAILABLE:
            break;
        case LocationProvider.OUT_OF_SERVICE:
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            break;
        default:
            break;
    }
}
 
Example 10
Source File: LocationSensor.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
  switch (status) {
    // Ignore TEMPORARILY_UNAVAILABLE, because service usually returns quickly.
    case LocationProvider.TEMPORARILY_UNAVAILABLE:
      StatusChanged(provider, "TEMPORARILY_UNAVAILABLE");
      break;
    case LocationProvider.OUT_OF_SERVICE:
      // If the provider we were listening to is no longer available,
      // find another.
      StatusChanged(provider, "OUT_OF_SERVICE");

      if (provider.equals(providerName)) {
        stopListening();
        RefreshProvider("onStatusChanged");
      }
      break;
    case LocationProvider.AVAILABLE:
      // If another provider becomes available and is one we hadn't known
      // about see if it is better than the one we're currently using.
      StatusChanged(provider, "AVAILABLE");
      if (!provider.equals(providerName) &&
          !allProviders.contains(provider)) {
        RefreshProvider("onStatusChanged");
      }
      break;
  }
}
 
Example 11
Source File: PassiveProvider.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int getStatus(Bundle extras) {
    if (mReportLocation) {
        return LocationProvider.AVAILABLE;
    } else {
        return LocationProvider.TEMPORARILY_UNAVAILABLE;
    }
}
 
Example 12
Source File: GPSLocationProvider.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
private String statusToString(int status)
{
	switch (status) {
	case LocationProvider.OUT_OF_SERVICE:
		return "OUT_OF_SERVICE";
	case LocationProvider.TEMPORARILY_UNAVAILABLE:
		return "TEMPORARILY_UNAVAILABLE";
	case LocationProvider.AVAILABLE:
		return "AVAILABLE:";
	}
	
	return "UNKNOWN";
}
 
Example 13
Source File: AndroidLocationManager.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private int convertStatus(int status) {
    switch (status) {
        case LocationProvider.AVAILABLE:
            return com.codename1.location.LocationManager.AVAILABLE;
        case LocationProvider.OUT_OF_SERVICE:
            return com.codename1.location.LocationManager.OUT_OF_SERVICE;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            return com.codename1.location.LocationManager.TEMPORARILY_UNAVAILABLE;
    }
    return com.codename1.location.LocationManager.OUT_OF_SERVICE;
}
 
Example 14
Source File: LocationHandler.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
public void onStatusChanged(String provider, int status, Bundle extras) {
	if (status != LocationProvider.AVAILABLE) {
		InfoView.setStatus(R.string.warte_auf_gps_verf_gbarkeit, 5000,
				gpsStatusInfo);
	} else {
		InfoView.clearStatus(gpsStatusInfo);
	}

}
 
Example 15
Source File: GeoPointActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    switch (status) {
        case LocationProvider.AVAILABLE:
            if (location != null) {
                locationDialog.setMessage(StringUtils.getStringRobust(this, R.string.location_accuracy,
                        "" + (int)location.getAccuracy()));
            }
            break;
        case LocationProvider.OUT_OF_SERVICE:
            break;
        case LocationProvider.TEMPORARILY_UNAVAILABLE:
            break;
    }
}
 
Example 16
Source File: Engine.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void onStatusChanged(final String pProvider, final int pStatus, final Bundle pExtras) {
	switch(pStatus) {
		case LocationProvider.AVAILABLE:
			this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.AVAILABLE, pExtras);
			break;
		case LocationProvider.OUT_OF_SERVICE:
			this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.OUT_OF_SERVICE, pExtras);
			break;
		case LocationProvider.TEMPORARILY_UNAVAILABLE:
			this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.TEMPORARILY_UNAVAILABLE, pExtras);
			break;
	}
}
 
Example 17
Source File: InstrumentationService.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onStatusChanged(String provider, int status,
                            Bundle extras) {
    Log.d(TAG, "LocationListener.onStatusChanged(...)");
    if (status == LocationProvider.AVAILABLE) {
        // Do nothing, we should get a location update soon which will
        // disable the listener.
    } else if (status == LocationProvider.OUT_OF_SERVICE ||
            status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
        removeListener(id);
        stopSelf(id);
    }
}
 
Example 18
Source File: MockProvider.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int getStatus(Bundle extras) {
    if (mHasStatus) {
        extras.clear();
        extras.putAll(mExtras);
        return mStatus;
    } else {
        return LocationProvider.AVAILABLE;
    }
}
 
Example 19
Source File: GnssLocationProvider.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void handleReportSvStatus(SvStatusInfo info) {
    mListenerHelper.onSvStatusChanged(
            info.mSvCount,
            info.mSvidWithFlags,
            info.mCn0s,
            info.mSvElevations,
            info.mSvAzimuths,
            info.mSvCarrierFreqs);

    // Log CN0 as part of GNSS metrics
    mGnssMetrics.logCn0(info.mCn0s, info.mSvCount);

    if (VERBOSE) {
        Log.v(TAG, "SV count: " + info.mSvCount);
    }
    // Calculate number of satellites used in fix.
    int usedInFixCount = 0;
    int maxCn0 = 0;
    int meanCn0 = 0;
    for (int i = 0; i < info.mSvCount; i++) {
        if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) {
            ++usedInFixCount;
            if (info.mCn0s[i] > maxCn0) {
                maxCn0 = (int) info.mCn0s[i];
            }
            meanCn0 += info.mCn0s[i];
        }
        if (VERBOSE) {
            Log.v(TAG, "svid: " + (info.mSvidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH) +
                    " cn0: " + info.mCn0s[i] +
                    " elev: " + info.mSvElevations[i] +
                    " azimuth: " + info.mSvAzimuths[i] +
                    " carrier frequency: " + info.mSvCarrierFreqs[i] +
                    ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) == 0
                            ? "  " : " E") +
                    ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) == 0
                            ? "  " : " A") +
                    ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) == 0
                            ? "" : "U") +
                    ((info.mSvidWithFlags[i] &
                            GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0
                            ? "" : "F"));
        }
    }
    if (usedInFixCount > 0) {
        meanCn0 /= usedInFixCount;
    }
    // return number of sats used in fix instead of total reported
    mLocationExtras.set(usedInFixCount, meanCn0, maxCn0);

    if (mNavigating && mStatus == LocationProvider.AVAILABLE && mLastFixTime > 0 &&
            SystemClock.elapsedRealtime() - mLastFixTime > RECENT_FIX_TIMEOUT) {
        // send an intent to notify that the GPS is no longer receiving fixes.
        Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION);
        intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, false);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
        updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE);
    }
}
 
Example 20
Source File: GnssLocationProvider.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void handleReportLocation(boolean hasLatLong, Location location) {
    if (location.hasSpeed()) {
        mItarSpeedLimitExceeded = location.getSpeed() > ITAR_SPEED_LIMIT_METERS_PER_SECOND;
    }

    if (mItarSpeedLimitExceeded) {
        Log.i(TAG, "Hal reported a speed in excess of ITAR limit." +
                "  GPS/GNSS Navigation output blocked.");
        if (mStarted) {
            mGnssMetrics.logReceivedLocationStatus(false);
        }
        return;  // No output of location allowed
    }

    if (VERBOSE) Log.v(TAG, "reportLocation " + location.toString());

    // It would be nice to push the elapsed real-time timestamp
    // further down the stack, but this is still useful
    location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    location.setExtras(mLocationExtras.getBundle());

    try {
        mILocationManager.reportLocation(location, false);
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException calling reportLocation");
    }

    if (mStarted) {
        mGnssMetrics.logReceivedLocationStatus(hasLatLong);
        if (hasLatLong) {
            if (location.hasAccuracy()) {
                mGnssMetrics.logPositionAccuracyMeters(location.getAccuracy());
            }
            if (mTimeToFirstFix > 0) {
                int timeBetweenFixes = (int) (SystemClock.elapsedRealtime() - mLastFixTime);
                mGnssMetrics.logMissedReports(mFixInterval, timeBetweenFixes);
            }
        }
    }

    mLastFixTime = SystemClock.elapsedRealtime();
    // report time to first fix
    if (mTimeToFirstFix == 0 && hasLatLong) {
        mTimeToFirstFix = (int) (mLastFixTime - mFixRequestTime);
        if (DEBUG) Log.d(TAG, "TTFF: " + mTimeToFirstFix);
        if (mStarted) {
            mGnssMetrics.logTimeToFirstFixMilliSecs(mTimeToFirstFix);
        }

        // notify status listeners
        mListenerHelper.onFirstFix(mTimeToFirstFix);
    }

    if (mSingleShot) {
        stopNavigating();
    }

    if (mStarted && mStatus != LocationProvider.AVAILABLE) {
        // For devices that use framework scheduling, a timer may be set to ensure we don't
        // spend too much power searching for a location, when the requested update rate is slow.
        // As we just recievied a location, we'll cancel that timer.
        if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mFixInterval < NO_FIX_TIMEOUT) {
            mAlarmManager.cancel(mTimeoutIntent);
        }

        // send an intent to notify that the GPS is receiving fixes.
        Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION);
        intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, true);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
        updateStatus(LocationProvider.AVAILABLE);
    }

    if (!hasCapability(GPS_CAPABILITY_SCHEDULING) && mStarted &&
            mFixInterval > GPS_POLLING_THRESHOLD_INTERVAL) {
        if (DEBUG) Log.d(TAG, "got fix, hibernating");
        hibernate();
    }
}