FileDocCategorySizeDatePackage
LocationProvider.javaAPI DocAndroid 5.1 API6735Thu Mar 12 22:22:30 GMT 2015android.location

LocationProvider

public class LocationProvider extends Object
An abstract superclass for location providers. A location provider provides periodic reports on the geographical location of the device.

Each provider has a set of criteria under which it may be used; for example, some providers require GPS hardware and visibility to a number of satellites; others require the use of the cellular radio, or access to a specific carrier's network, or to the internet. They may also have different battery consumption characteristics or monetary costs to the user. The {@link Criteria} class allows providers to be selected based on user-specified criteria.

Fields Summary
public static final int
OUT_OF_SERVICE
public static final int
TEMPORARILY_UNAVAILABLE
public static final int
AVAILABLE
public static final String
BAD_CHARS_REGEX
A regular expression matching characters that may not appear in the name of a LocationProvider
private final String
mName
private final com.android.internal.location.ProviderProperties
mProperties
Constructors Summary
public LocationProvider(String name, com.android.internal.location.ProviderProperties properties)
Constructs a LocationProvider with the given name. Provider names must consist only of the characters [a-zA-Z0-9].

throws
IllegalArgumentException if name contains an illegal character
hide


                                    
         
        if (name.matches(BAD_CHARS_REGEX)) {
            throw new IllegalArgumentException("provider name contains illegal character: " + name);
        }
        mName = name;
        mProperties = properties;
    
Methods Summary
public intgetAccuracy()
Returns a constant describing horizontal accuracy of this provider. If the provider returns finer grain or exact location, {@link Criteria#ACCURACY_FINE} is returned, otherwise if the location is only approximate then {@link Criteria#ACCURACY_COARSE} is returned.

        return mProperties.mAccuracy;
    
public java.lang.StringgetName()
Returns the name of this provider.

        return mName;
    
public intgetPowerRequirement()
Returns the power requirement for this provider.

return
the power requirement for this provider, as one of the constants Criteria.POWER_REQUIREMENT_*.

        return mProperties.mPowerRequirement;
    
public booleanhasMonetaryCost()
Returns true if the use of this provider may result in a monetary charge to the user, false if use is free. It is up to each provider to give accurate information.

        return mProperties.mHasMonetaryCost;
    
public booleanmeetsCriteria(Criteria criteria)
Returns true if this provider meets the given criteria, false otherwise.

        return propertiesMeetCriteria(mName, mProperties, criteria);
    
public static booleanpropertiesMeetCriteria(java.lang.String name, com.android.internal.location.ProviderProperties properties, Criteria criteria)

hide

        if (LocationManager.PASSIVE_PROVIDER.equals(name)) {
            // passive provider never matches
            return false;
        }
        if (properties == null) {
            // unfortunately this can happen for provider in remote services
            // that have not finished binding yet
            return false;
        }

        if (criteria.getAccuracy() != Criteria.NO_REQUIREMENT &&
                criteria.getAccuracy() < properties.mAccuracy) {
            return false;
        }
        if (criteria.getPowerRequirement() != Criteria.NO_REQUIREMENT &&
                criteria.getPowerRequirement() < properties.mPowerRequirement) {
            return false;
        }
        if (criteria.isAltitudeRequired() && !properties.mSupportsAltitude) {
            return false;
        }
        if (criteria.isSpeedRequired() && !properties.mSupportsSpeed) {
            return false;
        }
        if (criteria.isBearingRequired() && !properties.mSupportsBearing) {
            return false;
        }
        if (!criteria.isCostAllowed() && properties.mHasMonetaryCost) {
            return false;
        }
        return true;
    
public booleanrequiresCell()
Returns true if the provider requires access to an appropriate cellular network (e.g., to make use of cell tower IDs), false otherwise.

        return mProperties.mRequiresCell;
    
public booleanrequiresNetwork()
Returns true if the provider requires access to a data network (e.g., the Internet), false otherwise.

        return mProperties.mRequiresNetwork;
    
public booleanrequiresSatellite()
Returns true if the provider requires access to a satellite-based positioning system (e.g., GPS), false otherwise.

        return mProperties.mRequiresSatellite;
    
public booleansupportsAltitude()
Returns true if the provider is able to provide altitude information, false otherwise. A provider that reports altitude under most circumstances but may occassionally not report it should return true.

        return mProperties.mSupportsAltitude;
    
public booleansupportsBearing()
Returns true if the provider is able to provide bearing information, false otherwise. A provider that reports bearing under most circumstances but may occassionally not report it should return true.

        return mProperties.mSupportsBearing;
    
public booleansupportsSpeed()
Returns true if the provider is able to provide speed information, false otherwise. A provider that reports speed under most circumstances but may occassionally not report it should return true.

        return mProperties.mSupportsSpeed;