IT. Expert System.

Android Reference

LocationRequest


android.location

Class LocationRequest

  • All Implemented Interfaces:
    Parcelable


    public final class LocationRequest
    extends Object
    implements Parcelable
    A data object that contains quality of service parameters for requests to the LocationManager.

    LocationRequest objects are used to request a quality of service for location updates from the Location Manager.

    For example, if your application wants high accuracy location it should create a location request with setQuality(int) set to ACCURACY_FINE or POWER_HIGH, and it should set setInterval(long) to less than one second. This would be appropriate for mapping applications that are showing your location in real-time.

    At the other extreme, if you want negligible power impact, but to still receive location updates when available, then use setQuality(int) with POWER_NONE. With this request your application will not trigger (and therefore will not receive any power blame) any location updates, but will receive locations triggered by other applications. This would be appropriate for applications that have no firm requirement for location, but can take advantage when available.

    In between these two extremes is a very common use-case, where applications definitely want to receive updates at a specified interval, and can receive them faster when available, but still want a low power impact. These applications should consider POWER_LOW combined with a faster setFastestInterval(long) (such as 1 minute) and a slower setInterval(long) (such as 60 minutes). They will only be assigned power blame for the interval set by setInterval(long), but can still receive locations triggered by other applications at a rate up to setFastestInterval(long). This style of request is appropriate for many location aware applications, including background usage. Do be careful to also throttle setFastestInterval(long) if you perform heavy-weight work after receiving an update - such as using the network.

    Activities should strongly consider removing all location request when entering the background (for example at Activity.onPause()), or at least swap the request to a larger interval and lower quality. Future version of the location manager may automatically perform background throttling on behalf of applications.

    Applications cannot specify the exact location sources that are used by Android's Fusion Engine. In fact, the system may have multiple location sources (providers) running and may fuse the results from several sources into a single Location object.

    Location requests from applications with android.Manifest.permission#ACCESS_COARSE_LOCATION and not android.Manifest.permission#ACCESS_FINE_LOCATION will be automatically throttled to a slower interval, and the location object will be obfuscated to only show a coarse level of accuracy.

    All location requests are considered hints, and you may receive locations that are more accurate, less accurate, and slower than requested.

    • Field Detail

      • ACCURACY_FINE

        public static final int ACCURACY_FINE
        Used with setQuality(int) to request the most accurate locations available.

        This may be up to 1 meter accuracy, although this is implementation dependent.

        See Also:
        Constant Field Values
      • ACCURACY_BLOCK

        public static final int ACCURACY_BLOCK
        Used with setQuality(int) to request "block" level accuracy.

        Block level accuracy is considered to be about 100 meter accuracy, although this is implementation dependent. Using a coarse accuracy such as this often consumes less power.

        See Also:
        Constant Field Values
      • ACCURACY_CITY

        public static final int ACCURACY_CITY
        Used with setQuality(int) to request "city" level accuracy.

        City level accuracy is considered to be about 10km accuracy, although this is implementation dependent. Using a coarse accuracy such as this often consumes less power.

        See Also:
        Constant Field Values
      • POWER_NONE

        public static final int POWER_NONE
        Used with setQuality(int) to require no direct power impact (passive locations).

        This location request will not trigger any active location requests, but will receive locations triggered by other applications. Your application will not receive any direct power blame for location work.

        See Also:
        Constant Field Values
      • POWER_LOW

        public static final int POWER_LOW
        Used with setQuality(int) to request low power impact.

        This location request will avoid high power location work where possible.

        See Also:
        Constant Field Values
      • POWER_HIGH

        public static final int POWER_HIGH
        Used with setQuality(int) to allow high power consumption for location.

        This location request will allow high power location work.

        See Also:
        Constant Field Values
    • Constructor Detail

      • LocationRequest

        public LocationRequest()
    • Method Detail

      • create

        public static LocationRequest create()
        Create a location request with default parameters.

        Default parameters are for a low power, slowly updated location. It can then be adjusted as required by the applications before passing to the LocationManager

        Returns:
        a new location request
      • createFromDeprecatedProvider

        public static LocationRequest createFromDeprecatedProvider(String provider,
                                                   long minTime,
                                                   float minDistance,
                                                   boolean singleShot)
      • createFromDeprecatedCriteria

        public static LocationRequest createFromDeprecatedCriteria(Criteria criteria,
                                                   long minTime,
                                                   float minDistance,
                                                   boolean singleShot)
      • setQuality

        public LocationRequest setQuality(int quality)
        Set the quality of the request.

        Use with a accuracy constant such as ACCURACY_FINE, or a power constant such as POWER_LOW. You cannot request both and accuracy and power, only one or the other can be specified. The system will then maximize accuracy or minimize power as appropriate.

        The quality of the request is a strong hint to the system for which location sources to use. For example, ACCURACY_FINE is more likely to use GPS, and POWER_LOW is more likely to use WIFI & Cell tower positioning, but it also depends on many other factors (such as which sources are available) and is implementation dependent.

        setQuality(int) and setInterval(long) are the most important parameters on a location request.

        Parameters:
        quality - an accuracy or power constant
        Returns:
        the same object, so that setters can be chained
        Throws:
        InvalidArgumentException - if the quality constant is not valid
      • getQuality

        public int getQuality()
        Get the quality of the request.
        Returns:
        an accuracy or power constant
      • setInterval

        public LocationRequest setInterval(long millis)
        Set the desired interval for active location updates, in milliseconds.

        The location manager will actively try to obtain location updates for your application at this interval, so it has a direct influence on the amount of power used by your application. Choose your interval wisely.

        This interval is inexact. You may not receive updates at all (if no location sources are available), or you may receive them slower than requested. You may also receive them faster than requested (if other applications are requesting location at a faster interval). The fastest rate that that you will receive updates can be controlled with setFastestInterval(long).

        Applications with only the coarse location permission may have their interval silently throttled.

        An interval of 0 is allowed, but not recommended, since location updates may be extremely fast on future implementations.

        setQuality(int) and setInterval(long) are the most important parameters on a location request.

        Parameters:
        millis - desired interval in millisecond, inexact
        Returns:
        the same object, so that setters can be chained
        Throws:
        InvalidArgumentException - if the interval is less than zero
      • getInterval

        public long getInterval()
        Get the desired interval of this request, in milliseconds.
        Returns:
        desired interval in milliseconds, inexact
      • setFastestInterval

        public LocationRequest setFastestInterval(long millis)
        Explicitly set the fastest interval for location updates, in milliseconds.

        This controls the fastest rate at which your application will receive location updates, which might be faster than setInterval(long) in some situations (for example, if other applications are triggering location updates).

        This allows your application to passively acquire locations at a rate faster than it actively acquires locations, saving power.

        Unlike setInterval(long), this parameter is exact. Your application will never receive updates faster than this value.

        If you don't call this method, a fastest interval will be selected for you. It will be a value faster than your active interval (setInterval(long)).

        An interval of 0 is allowed, but not recommended, since location updates may be extremely fast on future implementations.

        If setFastestInterval(long) is set slower than setInterval(long), then your effective fastest interval is setInterval(long).

        Parameters:
        millis - fastest interval for updates in milliseconds, exact
        Returns:
        the same object, so that setters can be chained
        Throws:
        InvalidArgumentException - if the interval is less than zero
      • getFastestInterval

        public long getFastestInterval()
        Get the fastest interval of this request, in milliseconds.

        The system will never provide location updates faster than the minimum of getFastestInterval() and getInterval().

        Returns:
        fastest interval in milliseconds, exact
      • setExpireIn

        public LocationRequest setExpireIn(long millis)
        Set the duration of this request, in milliseconds.

        The duration begins immediately (and not when the request is passed to the location manager), so call this method again if the request is re-used at a later time.

        The location manager will automatically stop updates after the request expires.

        The duration includes suspend time. Values less than 0 are allowed, but indicate that the request has already expired.

        Parameters:
        millis - duration of request in milliseconds
        Returns:
        the same object, so that setters can be chained
      • setExpireAt

        public LocationRequest setExpireAt(long millis)
        Set the request expiration time, in millisecond since boot.

        This expiration time uses the same time base as SystemClock.elapsedRealtime().

        The location manager will automatically stop updates after the request expires.

        The duration includes suspend time. Values before SystemClock.elapsedRealtime() are allowed, but indicate that the request has already expired.

        Parameters:
        millis - expiration time of request, in milliseconds since boot including suspend
        Returns:
        the same object, so that setters can be chained
      • getExpireAt

        public long getExpireAt()
        Get the request expiration time, in milliseconds since boot.

        This value can be compared to SystemClock.elapsedRealtime() to determine the time until expiration.

        Returns:
        expiration time of request, in milliseconds since boot including suspend
      • setNumUpdates

        public LocationRequest setNumUpdates(int numUpdates)
        Set the number of location updates.

        By default locations are continuously updated until the request is explicitly removed, however you can optionally request a set number of updates. For example, if your application only needs a single fresh location, then call this method with a value of 1 before passing the request to the location manager.

        Parameters:
        numUpdates - the number of location updates requested
        Returns:
        the same object, so that setters can be chained
        Throws:
        InvalidArgumentException - if numUpdates is 0 or less
      • getNumUpdates

        public int getNumUpdates()
        Get the number of updates requested.

        By default this is Integer.MAX_VALUE, which indicates that locations are updated until the request is explicitly removed.

        Returns:
        number of updates
      • decrementNumUpdates

        public void decrementNumUpdates()
      • getProvider

        public String getProvider()
      • setSmallestDisplacement

        public LocationRequest setSmallestDisplacement(float meters)
      • getSmallestDisplacement

        public float getSmallestDisplacement()
      • describeContents

        public int describeContents()
        Description copied from interface: Parcelable
        Describe the kinds of special objects contained in this Parcelable's marshalled representation.
        Specified by:
        describeContents in interface Parcelable
        Returns:
        a bitmask indicating the set of special object types marshalled by the Parcelable.
      • qualityToString

        public static String qualityToString(int quality)
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 2410 / 96488209. Delta: 0.10689 с