Message:

Quick Start Guide for Backendless Geofencing

  1. Login to the Backendless developer console and create a new application called Geofence_Management.
    GF 1 - Quick Start Guide for Backendless Geofencing

  2. Click the Geolocation icon to step into the Backendless Geolocation Service.GF 2 - Quick Start Guide for Backendless Geofencing

  3. Click the Geofencing tab to obtain access to the Backendless Geofencing interface.GF 3 - Quick Start Guide for Backendless Geofencing

  4. Create a geofence using the drawing tools (line, rectangle or circle). GF 41 - Quick Start Guide for Backendless Geofencing

  5. Backendless supports three different geopoint events in relationship to a geofence: “On Enter”, “On Stay”, “On Exit”. These events occur when a geopoint (user’s device with your running application) enters, stays in or leaves a geofence. For each event you can configure an action which Backendless executes when an event occurs. A list of these actions is located in a dropdown menu for each event. GF 5 - Quick Start Guide for Backendless Geofencing

  6. To configure a geopoint action choose one from the dropdown menu. For this example, we choose the push notifications to be sent when a geopoint enters the created geofence. Once you click on the title of the chosen action a popup window appears.GF 6 - Quick Start Guide for Backendless Geofencing

  7. Select one of the device types you are configuring the actions for. Enter action configuration information such as: Ticker text, Content title and Content text for your push notification. Click the Save button. GF 7 - Quick Start Guide for Backendless Geofencing
    The geofence is ready. The next step is to create a client app where device location will be monitored for the geofence events. The Backendless SDK provides that capability.

  8. Now you can create an Android project in which you will add code to engage the configured geofencing actions. You can create the project using:

  •  a third-party software – in this case you have to add backendless.jar to your project. The file is available in the Backendless SDK for Android (You can download the SDK from the GitHub)
  • the Backendless Platform’s code generator in the Code Generation Section of the Backendless developer console. GF 81 - Quick Start Guide for Backendless Geofencing

9. To connect the created project with the Backendless backend switch to the Manage icon of the Backendless developer console and go to the App Settings section. Copy the default values of Application ID, Android Secret Key and a Version number and paste them into the app initialization code Backendless.initApp( applicationId, secretKey, version) of your created project: GF 9 - Quick Start Guide for Backendless Geofencing

10. Set up the client – side geofence monitoring for your project:

NOTICE:  Backendless supports two ways of the geofence monitoring: client – side and server-side monitoring. Remember that the server-side and the client – side monitoring cannot occur simultaneously. If you want to implement the client – side geofence monitoring you should set it up in your project.

To set up the the client-side geofence monitoring for your Android project:

  • Add the following permissions to your Android manifest:

<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />
<uses-permission android:name=”android.permission.RECEIVE_BOOT_COMPLETED” />

ACCESS_FINE_LOCATION – to allow application tracking location;

RECEIVE_BOOT_COMPLETED – to run service with tracking location when phone reboots.

  • Add service and receiver to your Android manifest:

11. Save a geopoint in the Backendless backend geolocation storage. The geopoint will be used to represent the location of your device. The geopoint should be created in your application before the code which starts location monitoring (reviewed later in this guide). Any metadata you add to the geopoint can be used in the geofence actions, however, in the same code below the metadata is added only for the demo purposes.

12. To start the server-side geofence monitoring for your Android project:

Backendless server-side geofence monitoring is set up and activated in the Backendless developer console:

  • click on the toggle in the “Is Active” column

  • click OK to start the Backendless server-side monitoring GF 101 - Quick Start Guide for Backendless Geofencing
  • Once the “In Active” toggle is switched to ON position the Backendless server-side monitoring starts.GF 11 - Quick Start Guide for Backendless Geofencing

13. To stop the server-side geofence monitoring or change it to the client -side monitoring switch  the “In Active” toggle to OFF position.

14. To start the client-site geofence monitoring you should input the code below to the same method where the geopoint has been created (see the step 11 above).

15. To stop the client-side geofence monitoring input the code below into the method which is invoked after the method that includes the call for the start of the client-side monitoring.

To download this demo sample: https://github.com/Backendless/Android-SDK/tree/master/samples/FenceDemo.