GeofencingApi

public interfaceGeofencingApi

This interface is deprecated.
Use the GoogleApi-based APIGeofencingClient instead.

The main entry point for interacting with the geofencing APIs.

The methods must be used in conjunction with aGoogleApiClient. E.g.


new GoogleApiClient.Builder(context)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build()

All methods are thread safe.

Public Method Summary

abstractPendingResult<Status>
addGeofences(GoogleApiClient client,GeofencingRequest geofencingRequest,PendingIntent pendingIntent)
Sets alerts to be notified when the device enters or exits one of the specified geofences.
abstractPendingResult<Status>
addGeofences(GoogleApiClient client,List<Geofence> geofences,PendingIntent pendingIntent)
abstractPendingResult<Status>
removeGeofences(GoogleApiClient client,List<String> geofenceRequestIds)
Removes geofences by their request IDs.
abstractPendingResult<Status>
removeGeofences(GoogleApiClient client,PendingIntent pendingIntent)
Removes all geofences associated with the givenpendingIntent.

Public Methods

public abstractPendingResult<Status> addGeofences(GoogleApiClient client,GeofencingRequest geofencingRequest,PendingIntent pendingIntent)

Sets alerts to be notified when the device enters or exits one of the specified geofences. If an existing geofence with the same request ID is already registered, the old geofence is replaced by the new one, and the newPendingIntentis used to generate intents for alerts.

Statusis returned when geofences are successfully added or failed to be added. Refer to GeofenceStatusCodes for possible errors when adding geofences.

When a geofence transition (for example, entering or exiting) matches one of the transition filter (see Geofence.Builder.setTransitionTypes(int)) in the given geofence list, an intent is generated using the given pending intent. You can call GeofencingEvent.fromIntent(Intent)to get the transition type, geofences that triggered this intent and the location that triggered the geofence transition.

In case network location provider is disabled by the user, the geofence service will stop updating, all registered geofences will be removed and an intent is generated by the provided pending intent. In this case, theGeofencingEvent created from this intent represents an error event, whereGeofencingEvent.hasError() returnstrueand GeofencingEvent.getErrorCode()returns GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE.

This method requires Manifest.permission.ACCESS_FINE_LOCATION.

Parameters
client an existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
geofencingRequest geofencing request that include a list of geofences to be added and related triggering behavior. The request must be created using GeofencingRequest.Builder.
pendingIntent a pending intent that will be used to generate an intent when matched geofence transition is observed
Throws
SecurityException if the app does not have Manifest.permission.ACCESS_FINE_LOCATIONpermission
NullPointerException ifgeofencingRequestorpendingIntentis null

public abstractPendingResult<Status> addGeofences(GoogleApiClient client,List<Geofence> geofences,PendingIntent pendingIntent)

This method is deprecated.
use addGeofences(GoogleApiClient, GeofencingRequest, PendingIntent)instead.

Sets alerts to be notified when the device enters or exits one of the specified geofences. If an existing geofence with the same request ID is already registered, the old geofence is replaced by the new one, and the newpendingIntentis used to generate intents for alerts.

Statusis returned when geofences are successfully added or failed to be added. Refer to GeofenceStatusCodes for possible errors when adding geofences.

When a geofence transition (for example, entering or exiting) matches one of the transition filter (see Geofence.Builder.setTransitionTypes(int)) in the given geofence list, an intent is generated using the given pending intent. You can call GeofencingEvent.fromIntent(Intent)to get the transition type, geofences that triggered this intent and the location that triggered the geofence transition.

In case network location provider is disabled by the user, the geofence service will stop updating, all registered geofences will be removed and an intent is generated by the provided pending intent. In this case, theGeofencingEvent created from this intent represents an error event, whereGeofencingEvent.hasError() returnstrueand GeofencingEvent.getErrorCode()returns GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE.

This method requires Manifest.permission.ACCESS_FINE_LOCATION.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
geofences a list of geofences to be added. The geofences must be created using Geofence.Builder.
pendingIntent a pending intent that will be used to generate an intent when matched geofence transition is observed
Throws
SecurityException if the app does not have Manifest.permission.ACCESS_FINE_LOCATIONpermission
IllegalArgumentException ifgeofencesisnullor empty
NullPointerException ifintentorlistenerisnull

public abstractPendingResult<Status> removeGeofences(GoogleApiClient client,List<String> geofenceRequestIds)

Removes geofences by their request IDs. Request ID is specified when you create a Geofence by calling Geofence.Builder.setRequestId(String).

Statusis returned when geofences are successfully removed or fail to be removed. Refer to GeofenceStatusCodes for possible errors when removing geofences.

This method requires Manifest.permission.ACCESS_FINE_LOCATION.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
geofenceRequestIds a list of request IDs of geofences that need to be removed
Throws
IllegalArgumentException ifgeofenceRequestIdsisnullor empty
SecurityException if the app does not have Manifest.permission.ACCESS_FINE_LOCATIONpermission
NullPointerException iflistenerisnull

public abstractPendingResult<Status> removeGeofences(GoogleApiClient client,PendingIntent pendingIntent)

Removes all geofences associated with the givenpendingIntent.

Warning: PendingIntent.equals(Object)is used for comparison. Please use PendingIntent.FLAG_UPDATE_CURRENT rather thanPendingIntent.FLAG_CANCEL_CURRENT when creating the pending intent, otherwise you will not get the same pending intent you provided to addGeofences(GoogleApiClient, List, PendingIntent)and thus the removal operation will remove nothing.

Statusis returned when geofences are successfully removed or fail to be removed. Refer to GeofenceStatusCodes for possible errors when removing geofences.

This method requires Manifest.permission.ACCESS_FINE_LOCATION.

Parameters
client An existing GoogleApiClient. It must be connected at the time of this call, which is normally achieved by calling GoogleApiClient.connect()and waiting for GoogleApiClient.ConnectionCallbacks#onConnectedto be called.
pendingIntent the pending intent associated with the geofences that need to be removed.
Throws
SecurityException if the app does not have Manifest.permission.ACCESS_FINE_LOCATIONpermission
NullPointerException ifintentorlisteneris null