Permissions
To use location APIs, your app must have access to fine or coarse location. Declare these permissions in your app’s manifest file. The following table lists Android permissions your app might request related to location services.| Permission | Description |
|---|---|
ACCESS_COARSE_LOCATIONRuntime permission that your app must request. | Allows app to access approximate location while in the foreground. |
ACCESS_FINE_LOCATIONRuntime permission that your app must request. | Allows app to access precise location while in the foreground. |
ACCESS_BACKGROUND_LOCATIONRuntime permission that your app must request. | Allows app to access location while in the background. Must use with ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. |
FOREGROUND_SERVICENormal permission that the system automatically grants. | Allows app to maintain a foreground status by showing a status bar notification. For details, see the Android developer documentation on Foreground services. |
Create an instance of A3LLocationProviderClient
To use A3L Location, create an instance of theA3LLocationProviderClient class. An A3LLocationProviderClient object provides the core methods of A3L Location. To create an instance of this class, use the A3LLocationServices.getA3LLocationProviderClient() method, as shown in the following code.
Get current location of the device
A primary use for location services is to determine the current location of the device. In A3L Location, to get the device’s current location, use thegetCurrentLocation() method. You can choose to get the current location and pass a priority indicator, or if your app has multiple needs, you can pass an A3LCurrentLocationRequest object. For details on A3LCurrentLocationRequest objects, see Get current location with A3LCurrentLocationRequest.
Get current location with priority
To usegetCurrentLocation() with priority, pass an A3LPriority constant. The following table lists the available A3LPriority constants. If you choose to prioritize higher accuracy in your app, the device uses more power. If you choose to prioritize lower power usage, the location has lower accuracy.
| A3L priority constant | Description |
|---|---|
A3LPriority.PRIORITY_BALANCED_POWER_ACCURACY | Priority is balanced between power and accuracy. |
A3LPriority.PRIORITY_HIGH_ACCURACY | Priority is given to high accuracy. Uses more device power. |
A3LPriority.PRIORITY_LOW_POWER | Priority is given to low power usage. Location is less accurate. |
A3LPriority.PRIORITY_PASSIVE | App doesn’t request location updates. |
CancellationToken object if you want to be able to cancel the location request. For more information on cancellation tokens, see Create a cancellation token.
Create a cancellation token (optional)
To be able to cancel a location request, you can pass aCancellationToken object in the getCurrentLocation() method. The following code shows an example of how to create a cancellation token. Using a cancellation token is optional.
Get current location with A3LCurrentLocationRequest
To pass more than one parameter in thegetCurrentLocation() request, you can build an A3LCurrentLocationRequest object that takes multiple parameters. For example, if you want to set both priority and a request interval, you can build the A3LCurrentLocationRequest and indicate the specific priority and request interval that fits the needs of your app.
The following code shows how to create an A3LCurrentLocationRequest object with multiple parameters. This example builds the object with granularity, max update age, priority, and duration.
A3LCurrentLocationRequest object can be built with, see the API Reference for A3LCurrentLocationRequest.Builder().
Get last known location of the device
To provide the most recent historical location currently available, use thegetLastLocation() method, as shown in the following code. This method returns null if there is no historical location available.
Get last known location with A3LLastLocationRequest
Similar to thegetCurrentLocation() method, you can customize your getLastLocation() request by passing an A3LLastLocationRequest object that has multiple parameters.
In your last known location request, you can define the granularity of the requested location (fine or coarse), or add a maximum age for the returned location. To do this, build an A3LLastLocationRequest object and pass it to the getLastLocation() method. The following example shows the object built with granularity and max update age.
A3LLastLocationRequest object can be built with, see the API Reference for A3LLastLocationRequest.Builder().

