FileDocCategorySizeDatePackage
LocationProvider.javaAPI DocAndroid 1.5 API5552Wed May 06 22:42:00 BST 2009android.location

LocationProvider

public abstract 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
private static final String
TAG
static final String
BAD_CHARS_REGEX
private String
mName
public static final int
OUT_OF_SERVICE
public static final int
TEMPORARILY_UNAVAILABLE
public static final int
AVAILABLE
Constructors Summary
LocationProvider(String name)
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


                                   
      
        if (name.matches(BAD_CHARS_REGEX)) {
            throw new IllegalArgumentException("name " + name +
                " contains an illegal character");
        }
        // Log.d(TAG, "Constructor: name = " + name);
        mName = name;
    
Methods Summary
public abstract 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.

public java.lang.StringgetName()
Returns the name of this provider.

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

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

public abstract 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.

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

        if ((criteria.getAccuracy() != Criteria.NO_REQUIREMENT) && 
            (criteria.getAccuracy() < getAccuracy())) {
            return false;
        }
        int criteriaPower = criteria.getPowerRequirement();
        if ((criteriaPower != Criteria.NO_REQUIREMENT) &&
            (criteriaPower < getPowerRequirement())) {
            return false;
        }
        if (criteria.isAltitudeRequired() && !supportsAltitude()) {
            return false;
        }
        if (criteria.isSpeedRequired() && !supportsSpeed()) {
            return false;
        }
        if (criteria.isBearingRequired() && !supportsBearing()) {
            return false;
        }
        return true;
    
public abstract booleanrequiresCell()
Returns true if the provider requires access to an appropriate cellular network (e.g., to make use of cell tower IDs), false otherwise.

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

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

public abstract 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.

public abstract 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.

public abstract 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.