Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to use Apple iBeacons with Android

How to use Apple iBeacons with Android

When Apple has announced their iBeacon technology I was curious if it would be possible to use it with Android. Hopefully it is not so hard to use this technology with Android. I've managed to create simple Proof of Concept and during my presentation I would like to show how to use this technology, its limitations, pros & cons and of course sample code.

Krakdroid 2013

Radek Piekarz

December 07, 2013
Tweet

More Decks by Radek Piekarz

Other Decks in Programming

Transcript

  1. Agenda  Anyone knows, anyone saw  Short history about

    iBeacons  iBeacons on Android – approach #1  iBeacons on Android – approach #2  Show me the code!  Problems and challenges  Summary  Q&A
  2. Bluetooth 4.0  Bluetooth low energy is an open standard

    developed by the Bluetooth SIG. It is designed to address the needs of new wireless applications, such as ultra-low power consumption, fast connection times, reliability, and security. Bluetooth low energy consumes 10 to 20 times less power than its previous version and is able to transmit data 50 times quicker than conventional Bluetooth solutions.
  3. iBeacons on Android – approach #2 1. How do Beacons

    really work? 2. How can access iBeacon’s data?
  4. iBeacon – how does it work?  iBeacons are usually

    small devices  They are broadcasting information every 0,2 – 1s  Smartphones scan for nearby iBeacons
  5. What data iBeacons send? d6 be 89 8e 40 24

    05 a2 17 6e 3d 71 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 52 ab 8d 38 a5
  6. What is the iBeacon Bluetooth Profile? d6 be 89 8e

    Access address for advertising data (this is always the same fixed value) 40 Advertising Channel PDU Header byte 0. Contains: (type = 0) 24 Advertising Channel PDU Header byte 1. Contains: (length = total bytes of the advertising payload + 6 bytes for the BLE mac address.) 05 a2 17 6e 3d 71 Bluetooth Mac address (note this is a spoofed address) 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 Bluetooth advertisement 52 ab 8d 38 a5 checksum
  7. Extracting data from the iBeacon  02 01 1a 1a

    ff 4c 00 02 15 – specification part  e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 – Proximity UUID (16 bytes)  00 00 – major (2 bytes)  00 00 – minor (2 bytes)  c5 - tx power (1 byte)
  8. How to calculate the distance from beacon #2  We

    have 2 types of information :  Moc z jaką nadaje beacon  Siłę sygnału, która do nas dotarła // rssi – from Android’s BLE API // txPower – read from scan data byte array – see previous slides double ratio = (rssi *1.0) / txPower; double exponentMultiplier = 1.5; double multiplier = 12.0; double distanceInMeters = Math.pow(multiplier, ratio*exponentMultiplier)/Math.pow(multiplier, exponentMultiplier); return distanceInMeters
  9. Show me the code #2 // Initializes Bluetooth adapter. final

    BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); private void scanLeDevice(final boolean enable) { if (enable) { // Stops scanning after a pre-defined scan period. mHandler.postDelayed(new Runnable() { @Override public void run() { mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); } }, SCAN_PERIOD); mScanning = true; mBluetoothAdapter.startLeScan(mLeScanCallback); } else { mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); } …
  10. Show me the code #3 // Device scan callback. private

    BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) { // do something } }; Parameters device Identifies the remote device rssi The RSSI value for the remote device as reported by the Bluetooth hardware. 0 if no RSSI value is available. scanRecord The content of the advertisement record offered by the remote device.
  11. What can we do with iBeacons?  Check if users

    has entered or left region defined by one or more iBeacons  Check how far user is from the particular iBeacon[s] Hmm… I’ll use Android background Service for searching and monitoring iBeacons!
  12. What about battery life?  Unlike iOS Android does not

    natively support iBeacons [yet]  We need to search for them, calculate the distance, check whether the user is within a given region  What if more applications will want to work with iBeacons at the same time?  Maybe we should scan for iBeacons only when the user is in an area that is defined by the geofence?
  13. What about NFC?  Enemies or complementary technologies?  Mobile

    payment = NFC  Tickets, entry cards = NFC?  Indoor navigation = iBeacons  Real world context = iBeacons/ NFC
  14. iBeacons – pros & cons Pros  We get access

    to the context of real-world  Amazing new opportunities in terms of access to needed information  They just works + easy setup Cons  No native support on Android  Possibility of battery drains  Currently small percentage of Android phones support Bluetooth LE
  15. Summary  iBeacons are a promising technology, which is worth

    exploring  New clients  NFC complementary  We can „easily” create indoor navigation  A lot of fun!
  16. Bonus – existing iBeacons Android SDKs  https://github.com/RadiusNetworks/android-ibeacon-service It might

    not work with all beacons  https://github.com/Estimote/Android-SDK (preview)  https://github.com/radzio/android-ibeacons (work in progress)