Search code examples
androidbluetooth-lowenergyibeacon-androidandroid-ibeacon

Beacon Library - Transmitter


I created a transmitter app with this Error code 2 in beacon transmitter for Android Beacon library code and able to transmit as iBeacon.

Problem 1: The app no longer able to transmit if i killed the app from recents(Should i call this from foreground service? Any in-built API from altbeacons library?)

Problem 2: I need to send a 10 character String to scanner after connection established, but setDataFields() only allowing for 6 digits.


Solution

  • It is a bit tricky to keep an Android app running in the background, which what you need to do to keep a transmitter going.

    The Android Beacon Library does this automatically for scanning purposes, so you could use the library's reference app as a starting point and put the transmission start in the onCreate method of the Application class.

    This would keep the transmitter going pretty much forever on Android 5-7. On Android 8 you are limited to running in the background for about 5 minutes out of every 15 unless you build a foreground service.

    EDIT

    If you wish to advertise several bytes of data, your best bet is to encode it in the 16 byte ID1 (ProximityUUID) field. You can reserve the first few bytes for determining if the beacon is yours, then use the last 10 bytes or so to encode your data. On the receiver side you can use identifier.getBytes() to convert your first identifier to a byte array so you can access data elements inside of it.