Code Monkey home page Code Monkey logo

android-sdk's Introduction

Android-SDK

Introduction

Beaconstac SDK is an easy way to enable proximity marketing and location analytics through an iBeacon-compliant BLE network.

Documentation

Please refer to the API documentation on the Beaconstac developer hub.

Integration with your existing project in Android Studio

  1. Download or clone this repo on your system.

  2. Copy the beaconstac-release.aar file into the libs directory of your app. Refer the included sample app for example.

  3. In the build.gradle file of your project, add the following in the repositories section

     flatDir {
         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'
  1. Refresh all Gradle projects.

  2. Create a file beaconstac.xml in the values folder 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>
    
  3. 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.
    
  4. Add uses-feature tag to app manifest:

     <uses-feature
     android:name="android.hardware.bluetooth_le"
     android:required="false" />
    
  5. 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"/>
    
  6. Add the Beaconstac BLEService to your app manifest:

    <service android:name="com.mobstac.beaconstac.core.MSBLEService" android:enabled="true"/>        
    
  7. 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.BeaconstacReceiver class and implement methods to handle the rangedBeacons, campedOnBeacon, exitedBeacon, triggeredRule, enteredRegion and exitedRegion events. The BeaconstacExample app contains an example of each type - directly using BeaconstacReceiver in the activity (this will require registering and unregistering it to receive intents in the activity itself), and extending BeaconstacReceiver and registering it to receive actions declared in the app manifest.

  8. Add the Beaconstac-provided actions in the app manifest that you wish to listen for, in your BroadcastReceiver. From the BeaconstacExample app 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>
    
  9. Add provider to the manifest. Please implement your own ContentProvider that extends com.mobstac.beaconstac.provider.MSContentProvider. From the BeaconstacExample app:

    <provider
        android:name=".MyContentProvider"
        android:authorities="@string/provider"
        android:enabled="true"
        android:exported="false"
        android:multiprocess="true"
        android:grantUriPermissions="true"
        android:syncable="true" >
    
  10. To monitor beacon regions, configure the UUID and region_identifier.

    // set region parameters (UUID and unique region identifier)
    Beaconstac bstacInstance = Beaconstac.getInstance(this);
    bstacInstance.setRegionParams("F94DBB23-2266-7822-3782-57BEAC0952AC",
            "com.mobstac.beaconstacexample");
    
  11. Call startRangingBeacons on the Beaconstac instance after configuring the params as mentioned in the previous step. The method will throw MSException on devices running Androi 17 or below.

    // start scanning
    bstacInstance.startRangingBeacons();
    
  12. If you want to stop scanning for beacons, call stopRangingBeacons on the Beaconstac instance. The method will throw MSException on devices running Androi 17 or below.

    // stop scanning
    bstacInstance.stopRangingBeacons();
    
  13. You can also dynamically set organization_id and api_key using setOrgId and setDevToken methods on the Beaconstac instance.

  14. Add MSGeofenceTransitionIntentService to manifest if you want to use the SDK's Geofence APIs.

    <service android:name="com.mobstac.beaconstac.core.MSGeofenceTransitionIntentService" />
    
  15. Implement the PlaceSyncReceiver before calling enableGeofences on the Beaconstac instance.

You can find more information and example usage in the BeaconstacExample app contained in the examples directory of this repo.

android-sdk's People

Contributors

bhashkarsharma avatar garimabatra avatar ravipratapm avatar vibinvarghesemobstac avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.