The main entry point for interacting with geofencing. In order to obtain an instance of
this class, see LocationServices
.
In order to use most geofencing APIs, clients are required to hold Manifest.permission.ACCESS_FINE_LOCATION
and
Manifest.permission.ACCESS_BACKGROUND_LOCATION
.
Public Method Summary
abstract Task<Void> |
addGeofences(GeofencingRequest
request, PendingIntent
pendingIntent)
Adds all geofences from the given
GeofencingRequest .
|
abstract Task<Void> | |
abstract Task<Void> |
removeGeofences(PendingIntent
pendingIntent)
Removes all geofences associated with given
PendingIntent .
|
Public Methods
public abstract Task<Void> addGeofences (GeofencingRequest request, PendingIntent pendingIntent)
Adds all geofences from the given GeofencingRequest
.
Geofences are uniquely identified by the request ID set in
Geofence.Builder.setRequestId(String)
and any geofence added here will
replace any prior geofence with the same ID. All geofences registered here will use the
given PendingIntent
to report their transitions. When receiving transitions,
GeofencingEvent.fromIntent(Intent)
may be used to retrieve information about
the transition.
The PendingIntent
passed in here must be mutable (ie, explicitly marked with PendingIntent.FLAG_MUTABLE
on Android S+).
Geofences are automatically removed when the client application is reset (when the client application is upgraded or removed, or the user force-restarts or force-quits it), or if the pending intent is canceled.
If this API fails, reference GeofenceStatusCodes
for possible errors. Clients are encouraged to only add one geofence at a time if they
need to recover or identify individual failures.
public abstract Task<Void> removeGeofences (List<String> requestIds)
Removes geofences by their request IDs.
public abstract Task<Void> removeGeofences (PendingIntent pendingIntent)
Removes all geofences associated with given PendingIntent
.
PendingIntent
equality can be more complex than expected, please see the PendingIntent
documentation for further information.