Reputation: 498
I have a BLE Beacon and instead of broadcasting constantly it just broadcasts a message when you push a button. It's a commissioning message. I'm looking all over the place but can't find a library that listens to Beacon messages.
I've taken a look and tried these solutions:
https://altbeacon.github.io/android-beacon-library/index.html
https://developers.google.com/nearby/messages/android/get-started
Is there a library that allows this?
Upvotes: 1
Views: 1478
Reputation: 64961
In order to detect a beacon message sent at the push of a button, you need the mobile app to be listening constantly ("scanning" is the BLE term) because it doesn't know when you are going to press the button.
You can use the open source Android Beacon Library mentioned in your question to do this. You would want to use its "beacon ranging" API which scans for beacons and tells your app what beacons it sees (if any) with a callback every second. If somebody hits the button the beacon, your app will get a callback to didRangeBeaconsInRegion
with a single beacon in the list. (If nobody hits the button, the app would get a callback with zero beacons in the list.)
A couple of important points:
You need to know the format of the beacon your hardware is transmitting (iBeacon, AltBeacon, Eddystone-UID, Eddystone-URL, etc.) so you can set up the scanning library to look for that kind of beacon.
You need to know what kind of identifier the hardware beacon sends out. Formats like iBeacon and Altbeacon transmit long hexadecimal UUID identifiers like "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6". You will need to know what it sends so you can tell if the beacon is yours. Otherwise your program will react even if somebody else's beacon is transmitting.
Full disclosure: I am the lead developer on the Android Beacon Library Open Source Project
Upvotes: 1