Beaconstac SDK is an easy way to enable proximity marketing and location analytics through an iBeacon-compliant BLE network.
Please refer to the API documentation on the Beaconstac developer hub.
-
Download or clone this repo on your system.
-
Copy the beaconstac-release.aar file into the
libsdirectory of your app. Refer the included sample app for example. -
In the
build.gradlefile of your project, add the following in the repositories sectionflatDir { dirs 'libs' }
4. In the build.gradle file of the app, add the following in the dependencies section:
compile (name: 'beaconstac-release', ext: 'aar')
compile 'com.mcxiaoke.volley:library:1.0.17'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.crittercism:crittercism-android-agent:5.0.6'
-
Refresh all Gradle projects.
-
Create a file
beaconstac.xmlin thevaluesfolder containing configurations for Beaconstac SDK.<?xml version="1.0" encoding="utf-8"?> <resources> <!-- whether rule processing is enabled --> <bool name="ruleProcessingEnabled">true</bool> <!-- time interval in seconds between rule syncs --> <integer name="ruleSyncInterval">86400</integer> <!-- events for which rules would be processed --> <string-array name="ruleEvents"> <item>CAMPED</item> <item>EXITED</item> </string-array> <!-- whether analytics is enabled --> <bool name="analyticsEnabled">true</bool> <!-- time interval in seconds between analytics posting --> <integer name="analyticsPostInterval">900</integer> <!-- Whether bug tracking is enabled --> <bool name="bugTrackingEnabled">true</bool> <!-- Beaconstac API token --> <string name="api_key"></string> <!-- Organization id --> <integer name="organization_id">0</integer> <!-- Provider authority --> <string name="provider">com.mobstac.beaconstacexample.provider</string> </resources> -
Note :
Please do ensure that the organization_id and the api_key have been filled into the beaconstac.xml. This can be found under account details on the manage.beaconstac.com portal. If this is not set, the rules will not get triggered. -
Add
uses-featuretag to app manifest:<uses-feature android:name="android.hardware.bluetooth_le" android:required="false" /> -
Add the following permissions to app manifest:
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> -
Add the Beaconstac BLEService to your app manifest:
<service android:name="com.mobstac.beaconstac.core.MSBLEService" android:enabled="true"/> -
Should you choose to implement your own BroadcastReceiver (required if beacon detection has to work when the app is not running), extend
com.mobstac.beaconstac.core.BeaconstacReceiverclass and implement methods to handle therangedBeacons,campedOnBeacon,exitedBeacon,triggeredRule,enteredRegionandexitedRegionevents. TheBeaconstacExampleapp contains an example of each type - directly usingBeaconstacReceiverin the activity (this will require registering and unregistering it to receive intents in the activity itself), and extendingBeaconstacReceiverand registering it to receiveactionsdeclared in the app manifest. -
Add the Beaconstac-provided actions in the app manifest that you wish to listen for, in your BroadcastReceiver. From the
BeaconstacExampleapp manifest:<receiver android:name=".BeaconstacExampleReceiver" android:exported="false"> <intent-filter> <action android:name="com.mobstac.beaconstac.intent.action.RANGED_BEACON" /> <action android:name="com.mobstac.beaconstac.intent.action.CAMPED_BEACON" /> <action android:name="com.mobstac.beaconstac.intent.action.EXITED_BEACON" /> <action android:name="com.mobstac.beaconstac.intent.action.TRIGGERED_RULE" /> <action android:name="com.mobstac.beaconstac.intent.action.ENTERED_REGION" /> <action android:name="com.mobstac.beaconstac.intent.action.EXITED_REGION" /> <action android:name="com.mobstac.beaconstac.intent.action.ENTERED_GEOFENCE" /> <action android:name="com.mobstac.beaconstac.intent.action.EXITED_GEOFENCE" /> </intent-filter> </receiver> -
Add
providerto the manifest. Please implement your own ContentProvider that extendscom.mobstac.beaconstac.provider.MSContentProvider. From theBeaconstacExampleapp:<provider android:name=".MyContentProvider" android:authorities="@string/provider" android:enabled="true" android:exported="false" android:multiprocess="true" android:grantUriPermissions="true" android:syncable="true" > -
To monitor beacon regions, configure the
UUIDandregion_identifier.// set region parameters (UUID and unique region identifier) Beaconstac bstacInstance = Beaconstac.getInstance(this); bstacInstance.setRegionParams("F94DBB23-2266-7822-3782-57BEAC0952AC", "com.mobstac.beaconstacexample"); -
Call
startRangingBeaconson theBeaconstacinstance after configuring the params as mentioned in the previous step. The method will throwMSExceptionon devices running Androi 17 or below.// start scanning bstacInstance.startRangingBeacons(); -
If you want to stop scanning for beacons, call
stopRangingBeaconson theBeaconstacinstance. The method will throwMSExceptionon devices running Androi 17 or below.// stop scanning bstacInstance.stopRangingBeacons(); -
You can also dynamically set
organization_idandapi_keyusingsetOrgIdandsetDevTokenmethods on theBeaconstacinstance. -
Add
MSGeofenceTransitionIntentServiceto manifest if you want to use the SDK's Geofence APIs.<service android:name="com.mobstac.beaconstac.core.MSGeofenceTransitionIntentService" /> -
Implement the
PlaceSyncReceiverbefore callingenableGeofenceson theBeaconstacinstance.
You can find more information and example usage in the BeaconstacExample app contained in the examples directory of this repo.
You can also obtain the SDK from Gradle using -
compile 'com.mobstac.beaconstac:beaconstac_sdk:1.4.2'