100

I have successfully modified the reference implementation app of the Android Beacon Library using the following beacon layout, so that it detects an iBeacon device that I have at hand:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.getBeaconParsers().add(new BeaconParser().
               setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
        beaconManager.bind(this);
    }
}

Being new to the internals of BLE packets, I'm not sure if this is the correct layout to use. The library endorses the AltBeacon standard and its documentation does not mention how to detect iBeacon devices.

  • Will this code detect all iBeacon devices? i.e. is the m: prefix too restrictive or is it the right byte sequence that matches the iBeacon spec?
  • Similarly, does the rest of the layout exactly match the iBeacon spec?

Reference:

Community
  • 1
  • 1
ento
  • 5,801
  • 6
  • 51
  • 69

2 Answers2

69

This worked for me: "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"

I don't think you need to match the 4c00 part because that is the manufacturer id, so you can probably leave that off and start with m:2-3=0215 Everything else looks right, and it seems to work.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
mobiledevbrick
  • 866
  • 8
  • 8
  • 8
    Thanks! From testing with Estimote beacons I can confirm that the `m:2-3=0215` change is indeed necessary. – matiash Aug 06 '14 at 14:58
  • 9
    This worked for me also..i used.. beaconManager.getBeaconParsers().add(new BeaconParser(). setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")); – John Sep 05 '14 at 06:05
  • This detects Estimote beacons very efficiently..but i have another Roximity Beacon..its not getting detected..what is the beaconLayout for roximity beacons – John Sep 05 '14 at 11:40
  • 2
    How do you read that layout? What is m, i and p? I have an out-of-the-box beacon bought from China. By using Bluetooth LE Scanner app, I was able to find the beacon's UUID, major and minor. But how do I find the UUID pattern to put it into `setBeaconLayout`? – emen Oct 14 '14 at 09:11
  • 3
    @AimanB Kindly refer this : http://stackoverflow.com/questions/25319682/correct-layout-to-detect-kontakt-beacon-on-android-with-altbeacon. In this, m: Manufacturer Data, i: Proximity UUID, i: Major Number, i : Minor Number, p: Signal Power,d : battery level. They represent byte offset. (You need to add 6 while counting).Eg: Manufacturer ID is in between 8th and 9th in the string "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24". – trueblue Dec 22 '14 at 09:59
  • 4
    is there a way to scan for any beacon around regardless if its estimote or not ? – N Jay Jan 13 '15 at 09:43
  • The iBeacon spec does require the manufacturer ID to be 0x4c00, so yes you do need that part. I have also tested beacons with manufacturer IDs set to other values and they are not detected by various apps. – Timmmm Nov 03 '15 at 16:03
  • There have been two proposed patterns and some confusion over which is correct: "m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24" and "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24 Can someone speak to which of these will detect iBeacons from all manufacturers? – Landon Aug 15 '19 at 15:43
  • @Landon I suspect either should work. One is just more verbose than the other. – swooby Jan 30 '20 at 22:11
5

You can download the iBeacon spec (click "Download Artwork and Specifications").

In the current version the Company ID must be 0x4C00, and the beacon type must be 0x0215. All other fields are required, and as you specified.

So yes, you are exactly correct and it will detect all compliant iBeacons.

OT: It also specifies that the advertising interval must be 100ms, but I seriously doubt all iBeacons stick to that.

Timmmm
  • 88,195
  • 71
  • 364
  • 509