GeofenceHardware.AddGeofence Method

Definition

Creates a circular geofence which is monitored by subsystems in the hardware.

[Android.Runtime.Register("addGeofence", "(IILandroid/hardware/location/GeofenceHardwareRequest;Landroid/hardware/location/GeofenceHardwareCallback;)Z", "")]
public bool AddGeofence (int geofenceId, Android.Hardware.Location.GeofenceMonitoringType monitoringType, Android.Hardware.Location.GeofenceHardwareRequest? geofenceRequest, Android.Hardware.Location.GeofenceHardwareCallback? callback);
[<Android.Runtime.Register("addGeofence", "(IILandroid/hardware/location/GeofenceHardwareRequest;Landroid/hardware/location/GeofenceHardwareCallback;)Z", "")>]
member this.AddGeofence : int * Android.Hardware.Location.GeofenceMonitoringType * Android.Hardware.Location.GeofenceHardwareRequest * Android.Hardware.Location.GeofenceHardwareCallback -> bool

Parameters

geofenceId
Int32

The id associated with the geofence.

monitoringType
GeofenceMonitoringType

The type of the hardware subsystem that should be used to monitor the geofence.

geofenceRequest
GeofenceHardwareRequest

The GeofenceHardwareRequest object associated with the geofence.

callback
GeofenceHardwareCallback

GeofenceHardwareCallback that will be use to notify the transition.

Returns

true when the geofence is successfully sent to the hardware for addition.

Attributes

Exceptions

when the geofence request type is not supported.

Remarks

Creates a circular geofence which is monitored by subsystems in the hardware.

When the device detects that is has entered, exited or is uncertain about the area specified by the geofence, the given callback will be called.

If this call returns true, it means that the geofence has been sent to the hardware. GeofenceHardwareCallback#onGeofenceAdd will be called with the result of the add call from the hardware. The GeofenceHardwareCallback#onGeofenceAdd will be called with the following parameters when a transition event occurs. <ul> <li> The geofence Id <li> The location object indicating the last known location. <li> The transition associated with the geofence. One of #GEOFENCE_ENTERED, #GEOFENCE_EXITED, #GEOFENCE_UNCERTAIN<li> The timestamp when the geofence transition occured. <li> The monitoring type (#MONITORING_TYPE_GPS_HARDWARE is one such example) that was used. </ul>

The geofence will be monitored by the subsystem specified by monitoring_type parameter. The application does not need to hold a wakelock when the monitoring is being done by the underlying hardware subsystem. If the same geofence Id is being monitored by two different monitoring systems, the same id can be used for both calls, as long as the same callback object is used.

Requires android.Manifest.permission#ACCESS_FINE_LOCATION permission when #MONITORING_TYPE_GPS_HARDWARE is used.

Requires android.Manifest.permission#LOCATION_HARDWARE permission to access geofencing in hardware.

This API should not be called directly by the app developers. A higher level api which abstracts the hardware should be used instead. All the checks are done by the higher level public API. Any needed locking should be handled by the higher level API.

Create a geofence request object using the methods in GeofenceHardwareRequest to set all the characteristics of the geofence. Use the created GeofenceHardwareRequest object in this call.

Java documentation for android.hardware.location.GeofenceHardware.addGeofence(int, int, android.hardware.location.GeofenceHardwareRequest, android.hardware.location.GeofenceHardwareCallback).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to