GithubHelp home page GithubHelp logo

vonwenm / android-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from estimote/android-fleet-management-sdk

0.0 2.0 0.0 21.86 MB

Estimote SDK for Android

Home Page: http://estimote.com

License: MIT License

Java 100.00%

android-sdk's Introduction

Estimote SDK for Android

Table of Contents

Overview

The Estimote SDK for Android is a library that allows interaction with Estimote beacons & stickers. The SDK system works on Android 4.3 or above and requires device with Bluetooth Low Energy (SDK's min Android SDK version is 9).

It allows for:

Start with Android tutorial for monitoring & ranging beacons.

Learn more:

Beacon ranging and monitoring

iBeacon allows for two basic interactions between apps and individual beacons or groups of beacons called regions:

  • Region monitoring: actions triggered on entering/exiting region’s range; works in the foreground, background, and even when the app is killed.
  • Ranging: actions triggered based on proximity to a beacon; works only in the foreground

Learn more about beacon ranging and monitoring

Ranging

Apps can use the startRanging method of the BeaconManager class to determine relative proximity of beacons in the region and can be updated when this distance changes. Ranging updates come every second to listeners registered with the setRangingListener method of the BeaconManager class. Ranging updates contain a list of currently found beacons. If a beacon goes out of range it will not be presented on this list.

Monitoring

Apps can use the startMonitoring method of the BeaconManager class to start monitoring regions. Monitoring updates come to listeners registered with the setMonitoringListener method of the BeaconManager class.

Monitoring is designed to perform periodic scans in the background. By default it scans for 5 seconds and sleeps for 25 seconds. This means that it can take by default up to 30 seconds to detect entering or exiting a region. Default behaviour can be changed via BeaconManager#setBackgroundScanPeriod.

Installation

Gradle via Maven Central

Estimote Android SDK is available on Maven Central. Declare in your Gradle's build.gradle dependency to this library.

dependencies {
  compile 'com.estimote:sdk:0.9.4@aar'
}

Initialize Estimote SDK in your Application class.

//  App ID & App Token can be taken from App section of Estimote Cloud.
EstimoteSDK.initialize(applicationContext, appId, appToken);
// Optional, debug logging.
EstimoteSDK.enableDebugLogging(true);

Manual installation

Eclipse users: Mark Murphy on his blog explained how to use aar format in Eclipse.

  1. Create libs directory inside your project and copy there estimote-sdk.aar.
  2. In your build.gradle add flatDir entry to your repositories
repositories {
  mavenCentral()
    flatDir {
      dirs 'libs'
    }
}
  1. Add dependency to Estimote SDK. All needed permissions (BLUETOOTH, BLUETOOTH_ADMIN and INTERNET) and services will be merged from SDK's AndroidManifest.xml to your application's AndroidManifest.xml.
dependencies {
  compile(name:'estimote-sdk', ext:'aar')
}
  1. Initialize Estimote SDK in your Application class if you are using Estimote Cloud.
//  App ID & App Token can be taken from App section of Estimote Cloud.
EstimoteSDK.initialize(applicationContext, appId, appToken);
// Optional, debug logging.
EstimoteSDK.enableDebugLogging(true);

Usage and demos

SDK Demos are located in Demos directory. You can easily build it with Gradle by typing gradlew installDebug (or gradlew.bat installDebug on Windows) in terminal when your device is connected to computer. If you use Android Studio you can just simply open build.gradle.

Demos include samples for ranging beacons, monitoring beacons, nearable discovery, calculating distance between beacon and the device and also changing minor value of the beacon.

Android M and runtime permissions

Depending on Android platform you need different permissions to be granted. It is recommended to implement future proof Android M runtime permissions model.

In order to reliably detect beacons following conditions must be met:

  • Bluetooth permissions are granted (android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN). This is done automatically if you use Estimote SDK.
  • BeaconService is declared in AndroidManifest.xml. This is done automatically if you use Estimote SDK.
  • If running on Android M or later, Location Services must be turned on.
  • If running on Android M or later and your app is targeting SDK < 23 (M), any location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION) must be granted for background beacon detection.
  • If running on Android M or later and your app is targeting SDK >= 23 (M), any location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION must be granted.

Sounds difficult? No worries. From time to time SDK will put warning in device logs what is missing. You can use the SystemRequirementsChecker#check method to determine which requirements are not met for beacon detection.

Use SystemRequirementsChecker#checkWithDefaultDialogs method in your activity for a convenient way to ask for all permissions and rights. It's all handled by the SDK, and should be of great help if you want to get up and running quickly.

Tutorials

Android tutorial for monitoring & ranging beacons

Android tutorial is available on Estimote Developer Docs. Tutorial is divided into three parts:

Quick start for nearables discovery

  private BeaconManager beaconManager = new BeaconManager(context);
  private String scanId;

  // Should be invoked in #onCreate.
  beaconManager.setNearableListener(new BeaconManager.NearableListener() {
    @Override public void onNearablesDiscovered(List<Nearable> nearables) {
      Log.d(TAG, "Discovered nearables: " + nearables);
    }
  });

  // Should be invoked in #onStart.
  beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
    @Override public void onServiceReady() {
      scanId = beaconManager.startNearableDiscovery();
    }
  });

  // Should be invoked in #onStop.
  beaconManager.stopNearableDiscovery(scanId);

  // When no longer needed. Should be invoked in #onDestroy.
  beaconManager.disconnect();

Quick start for Secure UUID

Ranging and region monitoring works transparently with Secure UUID enabled beacons. All you need is:

  1. Enable Secure UUID via Estimote app from Google Play or via SDK

connection = new BeaconConnection(…); connection.edit().set(connection.secureUUID(), true).commit(…);


2. Make sure you have initialised SDK with your App ID & App Token.
```java
//  App ID & App Token can be taken from App section of Estimote Cloud.
EstimoteSDK.initialize(applicationContext, appId, appToken);
  1. Use SecureRegion instead of Region when starting ranging or monitoring.
// Initialise BeaconManager as before.
// Find all *your* Secure UUID beacons in the vicinity.
beaconManager.startRanging(new SecureRegion(“regionId”, null, null, null));

// Remember that you can also range for other regions as well.
beaconManager.startRanging(new Region(“otherRegion”, null, null, null);

Quick start for Eddystone

Eddystone is an open protocol BLE protocol from Google. Estimote Beacons can broadcast the Eddystone packet.

With Estimote SDK you can:

  • find nearby Eddystone beacons (BeaconManager#startEddystoneScanning)
  • configure Eddystone ralated properties:
    • URL property of Eddystone-URL (see BeaconConnection#eddystoneUrl)
    • namespace & instance properties of Eddystone-UID (see BeaconConnection#eddystoneNamepsace, BeaconConnection#eddystoneInstance)
  • configure broadcasting scheme of beacon to Estimote Default, Eddystone-UID or Eddystone-URL (see BeaconConnection#broadcastingScheme)

SDK Examples contains Eddystone related samples.

Note that you can play with Estimote Beacons broadcasting the Eddystone packet and change their configuration via Estimote app on Google Play.

In order to start playing with Eddystone you need to update firmware of your existing Estimote beacons to 3.1.1. Easiest way is through Estimote app on Google Play. Then you can change broadcasting scheme on your beacon to Eddystone-URL or Eddystone-UID.

Following code snippet shows you how you can start discovering nearby Estimote beacons broadcasting Eddystone packet.

  private BeaconManager beaconManager = new BeaconManager(context);
  private String scanId;

  // Should be invoked in #onCreate.
  beaconManager.setEddystoneListener(new BeaconManager.EddystoneListener() {
    @Override public void onEddystonesFound(List<Eddystone> eddystones) {
      Log.d(TAG, "Nearby Eddystone beacons: " + eddystones);
    }
  });

  // Should be invoked in #onStart.
  beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
    @Override public void onServiceReady() {
      scanId = beaconManager.startEddystoneScanning();
    }
  });

  // Should be invoked in #onStop.
  beaconManager.stopEddystoneScanning(scanId);

  // When no longer needed. Should be invoked in #onDestroy.
  beaconManager.disconnect();

FAQ

There is Estimote SDK FAQ on wiki. There is also Estimote SDK for Android forum where you can post your questions.

Changelog

To see what has changed in recent versions of Estimote SDK for Android, see the CHANGELOG.

android-sdk's People

Contributors

bvermeule avatar deshraj avatar heypiotr avatar neurosnap avatar poberro avatar pt2121 avatar topgenorth avatar wiktor 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.