Added in API level 37

LocationButtonClient


public interface LocationButtonClient

android.app.permissionui.LocationButtonClient


A callback interface for receiving events about the location button. Location button allow users to grant precise location permission to an app.

An application must implement this interface to handle asynchronous events for location button session, such as session creation, permission results, and errors. An instance of this client is provided when calling LocationButtonProvider.openSession.

All callbacks on this interface are invoked serially on the Executor provided by the client app.

Summary

Public methods

abstract void onPermissionResult(boolean isGranted)

Callback for the result of a precise location permission grant after the user interacts with the location button.

abstract void onSessionError(Throwable cause)

Called when an error occurs either during the creation of the location button session LocationButtonProvider.openSession or after the session is created.

abstract void onSessionOpened(LocationButtonSession session)

Called when the location button session is successfully created.

Public methods

onPermissionResult

Added in API level 37
public abstract void onPermissionResult (boolean isGranted)

Callback for the result of a precise location permission grant after the user interacts with the location button.

When a user clicks the location button for the first time, the location button consent dialog is shown and this callback is invoked when users opt to share their location. However, this callback is not invoked if the user chooses not to share their location. In subsequent sessions after the initial consent, simply clicking on the location button will invoke this callback.

The system will grant temporary precise location permission and is valid only for the current session, this is similar to an "only this time" grant in permission request dialog.

In some cases, even after a user gives consent, precise location permission may not be granted due to system-level restrictions. In this scenario, the callback will be invoked with isGranted = false. It is recommended that the app handles this case gracefully by informing the user that the app cannot obtain precise location permission (or that the app can\u2019t access location).

Parameters
isGranted boolean: true if the permission is granted. false if the permission can't be granted.

onSessionError

Added in API level 37
public abstract void onSessionError (Throwable cause)

Called when an error occurs either during the creation of the location button session LocationButtonProvider.openSession or after the session is created.

This may happen if the remote service encounters an unrecoverable issue or the connection is lost. The session is automatically closed before this callback is invoked, so the application does not need to call LocationButtonSession.close().

Parameters
cause Throwable: The Throwable that describes the reason for the failure.
This value cannot be null.

onSessionOpened

Added in API level 37
public abstract void onSessionOpened (LocationButtonSession session)

Called when the location button session is successfully created.

The client is responsible for calling LocationButtonSession.close() on the session when it is no longer needed to release system resources.

Parameters
session LocationButtonSession: The newly created session.
This value cannot be null.