GeofencingEvent
Stay organized with collections
Save and categorize content based on your preferences.
Represents an event from the GeofencingClient
API. The event can be
- A geofence triggering event generated when a geofence transition happens.
- An error happens after geofences are registered and being monitored.
Inherited Method Summary
From class java.lang.Object
Public Methods
Parameters
intent
the intent to extract the geofencing event data from
Returns
- a
GeofencingEvent
object or null
if the given intent is null
or doesn't
contain geofencing event.
public int
getErrorCode
()
Returns the error code that explains the error that triggered the intent specified
in fromIntent(Intent)
.
public int
getGeofenceTransition
()
Returns the transition type of the geofence transition alert.
Returns
- -1 if the intent specified in
fromIntent(Intent)
is not generated for a transition alert; Otherwise
returns the GEOFENCE_TRANSITION_ flags value defined in Geofence
.
public List
< Geofence
>
getTriggeringGeofences
()
Returns a list of geofences that triggered this geofence transition alert.
Returns
- a list of geofences that triggered this geofence transition alert or
null
if the intent specified in fromIntent(Intent)
is not generated for a geofence transition alert
public Location
getTriggeringLocation
()
Gets the location that triggered the geofence transition.
Returns
- the location that triggered this geofence alert or
null
if it's not
included in the intent specified in fromIntent(Intent)
public boolean
hasError
()
Whether an error triggered this intent.
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\u003eGeofencingEvent\u003c/code\u003e objects represent events from the \u003ccode\u003eGeofencingClient\u003c/code\u003e API, such as geofence transitions or errors.\u003c/p\u003e\n"],["\u003cp\u003eThese events can be created from an Intent using the \u003ccode\u003efromIntent()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eYou can access information about the event, such as the triggering geofences, location, transition type, and any errors, using methods like \u003ccode\u003egetTriggeringGeofences()\u003c/code\u003e, \u003ccode\u003egetTriggeringLocation()\u003c/code\u003e, \u003ccode\u003egetGeofenceTransition()\u003c/code\u003e, and \u003ccode\u003egetErrorCode()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ehasError()\u003c/code\u003e method indicates whether the event was triggered by an error.\u003c/p\u003e\n"]]],["The `GeofencingEvent` class captures events from the `GeofencingClient` API, including geofence transitions and errors. Key actions involve creating a `GeofencingEvent` from an `Intent` using `fromIntent()`. Other actions include retrieving the error code via `getErrorCode()`, the transition type with `getGeofenceTransition()`, a list of geofences using `getTriggeringGeofences()`, and the triggering location by invoking `getTriggeringLocation()`. It can also check if an error has occurred by using `hasError()`.\n"],null,["# GeofencingEvent\n\npublic class **GeofencingEvent** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nRepresents an event from the [GeofencingClient](/android/reference/com/google/android/gms/location/GeofencingClient)\nAPI. The event can be\n\n- A geofence triggering event generated when a geofence transition happens.\n- An error happens after geofences are registered and being monitored. \n\n### Public Method Summary\n\n|------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [GeofencingEvent](/android/reference/com/google/android/gms/location/GeofencingEvent) | [fromIntent](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent))([Intent](//developer.android.com/reference/android/content/Intent.html) intent) Creates a [GeofencingEvent](/android/reference/com/google/android/gms/location/GeofencingEvent) object from the given intent. |\n| int | [getErrorCode](/android/reference/com/google/android/gms/location/GeofencingEvent#getErrorCode())() Returns the error code that explains the error that triggered the intent specified in [fromIntent(Intent)](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent)). |\n| int | [getGeofenceTransition](/android/reference/com/google/android/gms/location/GeofencingEvent#getGeofenceTransition())() Returns the transition type of the geofence transition alert. |\n| [List](//developer.android.com/reference/java/util/List.html)\\\u003c[Geofence](/android/reference/com/google/android/gms/location/Geofence)\\\u003e | [getTriggeringGeofences](/android/reference/com/google/android/gms/location/GeofencingEvent#getTriggeringGeofences())() Returns a list of geofences that triggered this geofence transition alert. |\n| [Location](//developer.android.com/reference/android/location/Location.html) | [getTriggeringLocation](/android/reference/com/google/android/gms/location/GeofencingEvent#getTriggeringLocation())() Gets the location that triggered the geofence transition. |\n| boolean | [hasError](/android/reference/com/google/android/gms/location/GeofencingEvent#hasError())() Whether an error triggered this intent. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public static [GeofencingEvent](/android/reference/com/google/android/gms/location/GeofencingEvent)\n**fromIntent** ([Intent](//developer.android.com/reference/android/content/Intent.html) intent)\n\nCreates a [GeofencingEvent](/android/reference/com/google/android/gms/location/GeofencingEvent)\nobject from the given intent. \n\n##### Parameters\n\n| intent | the intent to extract the geofencing event data from |\n|--------|------------------------------------------------------|\n\n##### Returns\n\n- a [GeofencingEvent](/android/reference/com/google/android/gms/location/GeofencingEvent) object or `null` if the given intent is `null` or doesn't contain geofencing event. \n\n#### public int **getErrorCode** ()\n\nReturns the error code that explains the error that triggered the intent specified\nin [fromIntent(Intent)](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent)). \n\n##### Returns\n\n- the error code specified in [GeofenceStatusCodes](/android/reference/com/google/android/gms/location/GeofenceStatusCodes) or `-1` if [hasError()](/android/reference/com/google/android/gms/location/GeofencingEvent#hasError()) returns `false`. \n\n#### public int **getGeofenceTransition** ()\n\nReturns the transition type of the geofence transition alert. \n\n##### Returns\n\n- -1 if the intent specified in [fromIntent(Intent)](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent)) is not generated for a transition alert; Otherwise returns the GEOFENCE_TRANSITION_ flags value defined in [Geofence](/android/reference/com/google/android/gms/location/Geofence). \n\n#### public [List](//developer.android.com/reference/java/util/List.html)\\\u003c[Geofence](/android/reference/com/google/android/gms/location/Geofence)\\\u003e\n**getTriggeringGeofences** ()\n\nReturns a list of geofences that triggered this geofence transition alert. \n\n##### Returns\n\n- a list of geofences that triggered this geofence transition alert or `null` if the intent specified in [fromIntent(Intent)](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent)) is not generated for a geofence transition alert \n\n#### public [Location](//developer.android.com/reference/android/location/Location.html)\n**getTriggeringLocation** ()\n\nGets the location that triggered the geofence transition. \n\n##### Returns\n\n- the location that triggered this geofence alert or `null` if it's not included in the intent specified in [fromIntent(Intent)](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent)) \n\n#### public boolean **hasError** ()\n\nWhether an error triggered this intent. \n\n##### Returns\n\n- `true` if an error triggered the intent specified in [fromIntent(Intent)](/android/reference/com/google/android/gms/location/GeofencingEvent#fromIntent(android.content.Intent)), otherwise `false`"]]