GeofencingClient
Stay organized with collections
Save and categorize content based on your preferences.
Public Methods
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eGeofencingClient\u003c/code\u003e is the primary entry point for interacting with geofencing functionalities within your Android application, obtained through \u003ccode\u003eLocationServices\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUsing this API requires the \u003ccode\u003eACCESS_FINE_LOCATION\u003c/code\u003e and \u003ccode\u003eACCESS_BACKGROUND_LOCATION\u003c/code\u003e permissions in your app's manifest.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to add, remove (by request ID or \u003ccode\u003ePendingIntent\u003c/code\u003e), and manage geofences for location-based triggers.\u003c/p\u003e\n"],["\u003cp\u003eGeofences are automatically removed under specific conditions like app reset, uninstallation, or pending intent cancellation.\u003c/p\u003e\n"]]],["The `GeofencingClient` manages geofences, requiring `ACCESS_FINE_LOCATION` and `ACCESS_BACKGROUND_LOCATION` permissions. It allows adding geofences via `addGeofences`, using a `GeofencingRequest` and a mutable `PendingIntent` for reporting transitions. Geofences are uniquely identified by a request ID. The client also supports removing geofences using either request IDs or a `PendingIntent` via `removeGeofences`. Geofences are automatically removed upon app reset.\n"],null,["# GeofencingClient\n\npublic interface **GeofencingClient** implements [HasApiKey](/android/reference/com/google/android/gms/common/api/HasApiKey)\\\u003c[Api.ApiOptions.NoOptions](/android/reference/com/google/android/gms/common/api/Api.ApiOptions.NoOptions)\\\u003e \nThe main entry point for interacting with geofencing. In order to obtain an instance of\nthis class, see [LocationServices](/android/reference/com/google/android/gms/location/LocationServices).\n\nIn order to use most geofencing APIs, clients are required to hold [Manifest.permission.ACCESS_FINE_LOCATION](//developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION)\nand [Manifest.permission.ACCESS_BACKGROUND_LOCATION](//developer.android.com/reference/android/Manifest.permission.html#ACCESS_BACKGROUND_LOCATION). \n\n### Public Method Summary\n\n|--------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e | [addGeofences](/android/reference/com/google/android/gms/location/GeofencingClient#addGeofences(com.google.android.gms.location.GeofencingRequest,%20android.app.PendingIntent))([GeofencingRequest](/android/reference/com/google/android/gms/location/GeofencingRequest) request, [PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html) pendingIntent) Adds all geofences from the given [GeofencingRequest](/android/reference/com/google/android/gms/location/GeofencingRequest). |\n| abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e | [removeGeofences](/android/reference/com/google/android/gms/location/GeofencingClient#removeGeofences(java.util.List\u003cjava.lang.String\u003e))([List](//developer.android.com/reference/java/util/List.html)\\\u003c[String](//developer.android.com/reference/java/lang/String.html)\\\u003e requestIds) Removes geofences by their request IDs. |\n| abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e | [removeGeofences](/android/reference/com/google/android/gms/location/GeofencingClient#removeGeofences(android.app.PendingIntent))([PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html) pendingIntent) Removes all geofences associated with given [PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html). |\n\nPublic Methods\n--------------\n\n#### public abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e **addGeofences** ([GeofencingRequest](/android/reference/com/google/android/gms/location/GeofencingRequest) request, [PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html) pendingIntent)\n\nAdds all geofences from the given [GeofencingRequest](/android/reference/com/google/android/gms/location/GeofencingRequest).\nGeofences are uniquely identified by the request ID set in [Geofence.Builder.setRequestId(String)](/android/reference/com/google/android/gms/location/Geofence.Builder#setRequestId(java.lang.String)) and any geofence added here will\nreplace any prior geofence with the same ID. All geofences registered here will use the\ngiven [PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html)\nto report their transitions. When receiving transitions, [GeofencingEvent.fromIntent(Intent)](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent)) may be used to retrieve information about\nthe transition.\n\nThe [PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html)\npassed in here must be mutable (ie, explicitly marked with [PendingIntent.FLAG_MUTABLE](//developer.android.com/reference/android/app/PendingIntent.html#FLAG_MUTABLE)\non Android S+).\n\nGeofences are automatically removed when the client application is reset (when the\nclient application is upgraded or removed, or the user force-restarts or force-quits\nit), or if the pending intent is canceled.\n\nIf this API fails, reference [GeofenceStatusCodes](/android/reference/com/google/android/gms/location/GeofenceStatusCodes)\nfor possible errors. Clients are encouraged to only add one geofence at a time if they\nneed to recover or identify individual failures. \n\n#### public abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e **removeGeofences** ([List](//developer.android.com/reference/java/util/List.html)\\\u003c[String](//developer.android.com/reference/java/lang/String.html)\\\u003e requestIds)\n\nRemoves geofences by their request IDs. \n\n#### public abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e **removeGeofences** ([PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html) pendingIntent)\n\nRemoves all geofences associated with given [PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html).\n\n[PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html)\nequality can be more complex than expected, please see the [PendingIntent](//developer.android.com/reference/android/app/PendingIntent.html)\ndocumentation for further information."]]