Beacons are bluetooth devices that can be sensed by a mobile device. Each Beacon has the following attributes:
Type | Description |
---|---|
Location | A reference to the Place or Zone where the beacon is placed. |
UUID | The unique identifier of the beacon. Mobile devices detect this UUID and use the UUID to identify the beacon. |
Major | Enter a 2-byte string to distinguish a set of beacons. For example, the Major value is commonly used to identify a Location. |
Minor | Enter a 2 byte string to identify individual beacons. For example, the Minor value is commonly used to identify beacons within a Zone. |
Typically, you set multiple Beacons at a location to share the same UUID, and use the major and minor values to distinguish Zones within the Location. For example, set the Major values of all the Beacons in a specific retail location to the same Major value, and then set the Minor values to identify a specific Zone within the retail location.
On this page:
Overview
Beacon searching and handling is included in the Beacon Kit.
How this works:
-
When the user’s device detects a supported beacon nearby, the beacon’s details are then sent to the server. This happens in the background.
-
If the beacon is configured on the server, a corresponding message will be sent back to the device in a form of push notification.
-
The library used to search for beacons is AltBeacon. The library is capable of detecting iBeacons, Eddystone UID, Eddystone TLM and Eddystone URL formats. However only iBeacons are supported by the SDK as of the moment.
Fully Custom UI
Integrate Beacons Kit into your Project
To include the Beacons kit, open the Gradle Scripts | build.gradle (Module: app)
and add the following to the
dependencies section:
implementation 'com.cheetahdigital.android:beacons:<version>'
Enable Beacon Detection
To enable the beacon detection feature, please follow the steps below:
-
Add this variable to your Application class:
private BeaconManager mBeaconManager;
-
Extend your Application class to
com.cheetahdigital.corekit.sdk.Application
public class Application extends Application {}
-
Add this set of lines in the onCreate method of your Application class:
public void onCreate() { boolean enableBeaconDetection = getResources().getBoolean(R.bool.detect_beacon_enabled); if (enableBeaconDetection) { // Initialize Beacon Manager mBeaconManager = new BeaconManager(this); } }
-
Add this set of methods on your Application class:
@Override public void onLogin() { super.onLogin(); if (mBeaconManager != null) { mBeaconManager.startMonitoring(); } } @Override public void onLogout() { super.onLogout(); if (mBeaconManager != null) { mBeaconManager.stopMonitoring(); BeaconHelper.clearAllBeaconIDS(getApplicationContext()); } }
-
Add this line in any xml values file (preferrably in strings.xml). This is so that you can disable the beacon detection anytime.
<bool name="detect_beacon_enabled">true</bool>
Edit Scan Settings
By default, the user’s device will scan for BLE devices for 1 second duration with 20 second intervals. These values can be replaced via these methods from BeaconManager
:
setBackgroundIntervalScanPeriod(long backgroundScanIntervalPeriod)
- call this to modify the interval between scans.setBackgroundDurationScanPeriod(long backgroundScanDurationPeriod)
- call this to modify the scan duration.
The set period for both methods should be in milliseconds.
Setting Beacon Threshold
By default, when the same beacon id is detected, it will take 4 hours before it will be detected again, unless the user logs out and then logs in again. This is to avoid spamming the user with the same notification, if the same beacon is detected. To configure beacon threshold, place this line:
<string name="beacon_threshold">2</string>
in any xml values file (preferrably in strings.xml).
The value denotes the hour interval before the user can receive notification from the same beacon id. In the example above, it will take 2 hours before the user can receive notification again.