Skip to content Skip to footer

Android – Geofence Attendance Check in/out

OVERVIEW

To check in/out users based on the location details provided in the login response.

To enable this feature we will be using Google’s Geofence.

Geofence will provide entrance and exit transition events of a particular location.

Code is written by considering there will be a single application inside a host application.

User’s logging will start after successful login & if the background location permission is enabled.

When a user lands in a predefined location area then automatically check in record will be submitted to server and likewise for checkout as well when user exits from geofence radius.

Added Geofence will be removed once user logout from the app.

Changes made in App (Android):

  1. Add Broadcast receiver in manifest to listen for transition events.
  2. ACCESS_BACKGROUND_LOCATION: Permission required to work Geofence.

As Geofence accesses location in the background.

  1. Check whether this account is geofence attendance enabled or not by checking the key background_location_required: true/false in account manifest. E.g You can check this in the login api response.
  2. Obtain geofence radius, latitude and longitude of center point from app metadata value.

Login response will contain below two keys to setup attendance geofence:

  1. background_location_required: true/false (true: to enable background location access for geofencing)
    1. This must be true to work geofence.
    2. This will ask user to enable background location permission access (Allow all the time option must be selected)
  1. geofence_attendance_form_id: FORM_ID OF ATTENDANCE FORM
    1. This is the form id of whose record will be sent to the server to mark Check In/Out.
    2. Check in type choice list widget value will be like this only : Check In / Check Out

When submitting the record to the server make sure that the markup fields are filled correctly.

Attendance choice list value: Check In / Check Out

  • To set this value, find a choice list from the attendance form which doesn’t have a markup field.
  • Set its respective value i.e Check In / Check Out in stringified JSONArray format

E.g 

[
…,
{
 "type": "choicelist-widget",
 "prompt": "Type",
 "identifier": "Type",
 "sub_type": "fixed_list",
 "unit": "",
 "value": "[\"Check Out\"]"
}
]

Attendance form object created while check in and check out via geofence:

[
 {
   "type": "verification-widget",
   "prompt": "Verification",
   "identifier": "Verify_IN",
   "sub_type": "face",
   "value": ""
 },
// Value choice list widget
 {
   "type": "choicelist-widget",
   "prompt": "Type",
   "identifier": "Type",
   "sub_type": "fixed_list",
   "unit": "",
   "value": "[\"Check Out\"]"
 },
 {
   "type": "timestamp-widget",
   "prompt": "Timestamp IN",
   "identifier": "Timestamp_IN",
   "sub_type": "timestamp",
   "value": "2021-05-22 07:25:42"
 },
 {
   "type": "capturegpslocation-widget",
   "prompt": "Location",
   "identifier": "Location_IN",
   "sub_type": "number",
   "value": "[{\"type\":\"marker\",\"value\":[{\"lat\":18.6282779,\"long\":73.8558751}],\"note\":\"\"}]"
 },
 {
   "type": "verification-widget",
   "prompt": "Verify OUT",
   "identifier": "Verify_OUT",
   "sub_type": "face",
   "value": ""
 },
 {
   "type": "capturegpslocation-widget",
   "prompt": "Location OUT",
   "identifier": "Location_OUT",
   "sub_type": "number",
   "value": "[{\"type\":\"marker\",\"value\":[{\"lat\":18.6282779,\"long\":73.8558751}],\"note\":\"\"}]"
 },
 {
   "type": "timestamp-widget",
   "prompt": "Timestamp OUT",
   "identifier": "Timestamp_OUT",
   "sub_type": "timestamp",
   "value": "2021-05-22 07:25:42"
 },
// User reference list widget value, its value will be set by markup @(user}.
 {
   "type": "choicelist-widget",
   "prompt": "User",
   "identifier": "User_2",
   "sub_type": "reference_list",
   "unit": "",
   "value": "[{\"fot\":\"Tabco User2\",\"foid\":\"7f3cd1b4356c4fcdb4a8a45d51d6e36f\",\"fost\":\"tabco.testuser1@axonator.com\",\"id\":\"7f3cd1b4356c4fcdb4a8a45d51d6e36f\"}]"
 },
 {
   "type": "yes_no-widget",
   "prompt": "Merged",
   "identifier": "Merged",
   "sub_type": "yes_no",
   "value": "0"
 },
 {
   "type": "computedvalue-widget",
   "prompt": "Duration",
   "identifier": "Duration",
   "sub_type": "text",
   "value": ""
 },
 {
   "type": "textbox-widget",
   "prompt": "User Id",
   "identifier": "User_Id",
   "sub_type": "text",
   "value": "",
   "value_without_mask": "",
   "verification_status": "NOT_DONE"
 },
 {
   "type": "timestamp-widget",
   "prompt": "Attendance created on",
   "identifier": "created_on_248174",
   "sub_type": "timestamp",
   "value": "2021-05-22 07:25:42"
 },
 {
   "type": "choicelist-widget",
   "prompt": "Attendance creator",
   "identifier": "creator_248174",
   "sub_type": "reference_list",
   "unit": "",
   "value": "[{\"fot\":\"Tabco User2\",\"foid\":\"7f3cd1b4356c4fcdb4a8a45d51d6e36f\",\"fost\":\"tabco.testuser1@axonator.com\",\"id\":\"7f3cd1b4356c4fcdb4a8a45d51d6e36f\"}]"
 },
 {
   "type": "capturegpslocation-widget",
   "prompt": "Attendance created at",
   "identifier": "created_at_248174",
   "sub_type": "number",
   "value": "[{\"type\":\"marker\",\"value\":[{\"lat\":18.6282779,\"long\":73.8558751}],\"note\":\"\"}]"
 }
]

Was This Article Helpful?

0
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami