android.location.LocationProvider Java Examples

The following examples show how to use android.location.LocationProvider. 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: LocationService.java    From Androzic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
	if (enableMockLocations)
		return;

	if (LocationManager.GPS_PROVIDER.equals(provider))
	{
		switch (status)
		{
			case LocationProvider.TEMPORARILY_UNAVAILABLE:
			case LocationProvider.OUT_OF_SERVICE:
				tearTrack();
				updateNotification();
				break;
		}
	}
}
 
Example #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: DiagnosticsActivity.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private void probeLocation() {
    StringBuilder sb = new StringBuilder();

    List<String> allProviders = lm.getAllProviders();
    for (String s : allProviders) {
        sb.append(s).append("\n");
        LocationProvider provider = lm.getProvider(s);
        sb.append("Name " + provider.getName()).append("\n");
        sb.append("Cell " + provider.requiresCell()).append("\n");
        sb.append("Network " + provider.requiresNetwork()).append("\n");
        sb.append("Satellite " + provider.requiresSatellite()).append("\n");
        sb.append("Altitude " + provider.supportsAltitude()).append("\n");
        sb.append("Bearing " + provider.supportsBearing()).append("\n");
        sb.append("Speed " + provider.supportsSpeed()).append("\n\n");
        //GpsStatus gpsStatus = lm.getGpsStatus(null);
        //gpsStatus.
    }
    output.setText(sb.toString());
}
 
Example #11
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 #12
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 #13
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 #14
Source File: LocationService.java    From io.appium.settings with Apache License 2.0 5 votes vote down vote up
private MockLocationProvider createLocationManagerMockProvider(LocationManager locationManager, LocationProvider locationProvider) {
    return new LocationManagerProvider(locationManager,
            locationProvider.getName(),
            locationProvider.requiresNetwork(),
            locationProvider.requiresSatellite(),
            locationProvider.requiresCell(),
            locationProvider.hasMonetaryCost(),
            locationProvider.supportsAltitude(),
            locationProvider.supportsSpeed(),
            locationProvider.supportsBearing(),
            locationProvider.getPowerRequirement(),
            locationProvider.getAccuracy());
}
 
Example #15
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 #16
Source File: AndroidLocationOutput.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
protected AndroidLocationOutput(AndroidSensorsDriver parentModule, LocationManager locManager, LocationProvider locProvider)
{
    super(parentModule);
    this.locManager = locManager;
    this.locProvider = locProvider;        
    this.name = locProvider.getName().replaceAll(" ", "_") + "_data";
}
 
Example #17
Source File: SensorMLBuilder.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
public PhysicalComponent getComponentDescription(LocationManager locManager, LocationProvider locProvider)
{
    PhysicalComponent comp = smlFac.newPhysicalComponent();
    comp.setId("LOC_" + formatId(locProvider.getName()));
    comp.setName(locProvider.getName());
    return comp;
}
 
Example #18
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 #19
Source File: AndroidLocationManager.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #20
Source File: LocationProviderProxy.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private LocationProvider a()
{
    LocationProvider locationprovider;
    if (a == null)
    {
        break MISSING_BLOCK_LABEL_26;
    }
    locationprovider = a.getProvider(b);
    return locationprovider;
    Throwable throwable;
    throwable;
    throwable.printStackTrace();
    return null;
}
 
Example #21
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 #22
Source File: LocationManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Return all providers by name, that match criteria and are optionally
 * enabled.
 * Can return passive provider, but never returns fused provider.
 */
@Override
public List<String> getProviders(Criteria criteria, boolean enabledOnly) {
    int allowedResolutionLevel = getCallerAllowedResolutionLevel();
    ArrayList<String> out;
    int uid = Binder.getCallingUid();
    long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            out = new ArrayList<>(mProviders.size());
            for (LocationProviderInterface provider : mProviders) {
                String name = provider.getName();
                if (LocationManager.FUSED_PROVIDER.equals(name)) {
                    continue;
                }
                if (allowedResolutionLevel >= getMinimumResolutionLevelForProviderUse(name)) {
                    if (enabledOnly
                            && !isAllowedByUserSettingsLocked(name, uid, mCurrentUserId)) {
                        continue;
                    }
                    if (criteria != null && !LocationProvider.propertiesMeetCriteria(
                            name, provider.getProperties(), criteria)) {
                        continue;
                    }
                    out.add(name);
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }

    if (D) Log.d(TAG, "getProviders()=" + out);
    return out;
}
 
Example #23
Source File: LocationService.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (enableMockLocations && BuildConfig.DEBUG)
        return;

    if (LocationManager.GPS_PROVIDER.equals(provider)) {
        switch (status) {
            case LocationProvider.TEMPORARILY_UNAVAILABLE:
            case LocationProvider.OUT_OF_SERVICE:
                tearTrack();
                updateNotification();
                break;
        }
    }
}
 
Example #24
Source File: LocationService.java    From AndroidLocationStarterKit with MIT License 5 votes vote down vote up
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    if (provider.equals(LocationManager.GPS_PROVIDER)) {
        if (status == LocationProvider.OUT_OF_SERVICE) {
            notifyLocationProviderStatusUpdated(false);
        } else {
            notifyLocationProviderStatusUpdated(true);
        }
    }
}
 
Example #25
Source File: LocationRetriever.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStart(@NonNull LifecycleOwner owner) {
  if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
      ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
  {
    Log.w(TAG, "No location permission!");
    failureListener.onFailure();
  }

  LocationProvider provider = locationManager.getProvider(LocationManager.GPS_PROVIDER);

  if (provider == null) {
    Log.w(TAG, "GPS provider is null. Trying network provider.");
    provider = locationManager.getProvider(LocationManager.NETWORK_PROVIDER);
  }

  if (provider == null) {
    Log.w(TAG, "Network provider is null. Unable to retrieve location.");
    failureListener.onFailure();
    return;
  }

  Location lastKnown = locationManager.getLastKnownLocation(provider.getName());

  if (lastKnown != null) {
    Log.i(TAG, "Using last known location.");
    successListener.onSuccess(lastKnown);
  } else {
    Log.i(TAG, "No last known location. Requesting a single update.");
    locationManager.requestSingleUpdate(provider.getName(), this, null);
  }
}
 
Example #26
Source File: LocationManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean providerMeetsCriteria(String provider, Criteria criteria) {
    LocationProviderInterface p = mProvidersByName.get(provider);
    if (p == null) {
        throw new IllegalArgumentException("provider=" + provider);
    }

    boolean result = LocationProvider.propertiesMeetCriteria(
            p.getName(), p.getProperties(), criteria);
    if (D) Log.d(TAG, "providerMeetsCriteria(" + provider + ", " + criteria + ")=" + result);
    return result;
}
 
Example #27
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 #28
Source File: LocationSensor.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private boolean startProvider(final String providerName) {
  this.providerName = providerName;
  LocationProvider tLocationProvider = locationManager.getProvider(providerName);
  if (tLocationProvider == null) {
    Log.d(LOG_TAG, "getProvider(" + providerName + ") returned null");
    return false;
  }
  stopListening();
  locationProvider = tLocationProvider;
  locationManager.requestLocationUpdates(providerName, timeInterval,
        distanceInterval, myLocationListener);
  listening = true;
  return true;
}
 
Example #29
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 #30
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;
    }
}