1

Am referring to https://github.com/AltBeacon/android-beacon-library-reference for my project.

Through the documentation and some comments, I figured out that they by default they receive altBeacon signal. I wanted to know, how can we personalize it to read other different beacon formats such as Eddystone and iBeacon.

As it's open source i'll like to stick to it and later personalize(update) accordingly.

For example we need to set the beacon layout using below code :

beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));

Edit: I changed the setBeaconLayout part of the code,as suggested in an answer. Still it's not working.

I used the following piece of code(Am referring to https://github.com/AltBeacon/android-beacon-library-reference). I added those setBeaconLayout part to receive eddystone signal which sadly,am not receiving. But if I remove the same, I can receive altBeacon signals.

 public void onCreate() {
    super.onCreate();
    BeaconManager beaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
    beaconManager.getBeaconParsers().clear();
    beaconManager.getBeaconParsers().add(new BeaconParser().
    setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT)); //for Eddystone... 
    Log.d(TAG, "setting up background monitoring for beacons and power saving");
    Region region = new Region("backgroundRegion",null, null, null);
    regionBootstrap = new RegionBootstrap(this, region);
    backgroundPowerSaver = new BackgroundPowerSaver(this);
}

Can anyone help me in this? How do I make my app receive eddystone signal?

P.s Can someone also give a list of sample setBeaconLayout part for different signals. Am assuming that if we just change that part, we can receive signals (for the signal format for which we set the layout.

Many Thanks in advance.

driftking9987
  • 1,673
  • 1
  • 32
  • 63

3 Answers3

0

Recently i was struggling to achieve the same ,and got a solution to it here. Also you need to configure your beacon by putting it in Eddystone UUID mode. By just changing the setBeaconLayout we wont be able to detect different beacon format .Eg - Eddystone UID format is not the same as iBeacon UID format. You can explore different beacon formats by using something like, mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));.

So your code should look like,

public class MyApplication extends Application implements BootstrapNotifier {
private static final String TAG = "MyApplication";
private RegionBootstrap regionBootstrap;
private BackgroundPowerSaver backgroundPowerSaver;
private BeaconManager mBeaconManager;

public void onCreate() {
    super.onCreate();
    mBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
    mBeaconManager.getBeaconParsers().clear();
     mBeaconManager.getBeaconParsers().add(new BeaconParser().
        setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
    Region region = new Region("my-beacon-region", null, null, null);

    regionBootstrap = new RegionBootstrap(this, region);

    backgroundPowerSaver = new BackgroundPowerSaver(this);
}

@Override
public void didEnterRegion(Region region) {

        Log.d("radbeacon", "Beacon detected in region");
}

@Override
public void didExitRegion(Region region) {

    Log.d("radbeacon", "Beacon out of region");
}

@Override
public void didDetermineStateForRegion(int i, Region region) {
      //Ignore
    }

}

Also don't forget to put your beacon in Eddystone UID mode and then turn the beacon on so that it can be detected by your app.

Community
  • 1
  • 1
Parag Kadam
  • 3,620
  • 5
  • 25
  • 51
  • I tried adding `BeaconParser.EDDYSTONE_UID_LAYOUT` but it's not really helping me. Am using the locate app to send eddystone signals but the app is not really receiving them. And how do you think one's approach should be on configuring the "APP" to read either kind of beacons. – driftking9987 Nov 14 '15 at 13:15
  • Check this link to know more about beacons here -> https://www.youtube.com/watch?v=TZf4WquRGJU – Parag Kadam Nov 15 '15 at 04:43
  • Dont we need `mBeaconManager.bind(this);` ? Btw I tried adding this but it just wont let me add that! And thanks for video, going through that. – driftking9987 Nov 15 '15 at 07:36
  • I did the same exact thing but am not able to detect eddytsone UID format. If I remove the `setBeaconLayout` part, am able to detect the altBeacon format as that's the default one. Can you please tell what's wrong? – driftking9987 Nov 15 '15 at 09:06
  • No `mBeaconManager.bind(this)` is not required here ,if you add `mBeaconManager.bind(this)` to your code then your beacon will only be detected when that particular activity is in the foreground. Using the above code you will not only be able to detect a beacon in the foreground but also in the background(When your app is not running). – Parag Kadam Nov 15 '15 at 12:01
  • Also what kind of a beacon are you using and have you configured it in the uddystone uid mode? – Parag Kadam Nov 15 '15 at 12:01
  • Am using locate app on my android phone. And Yeah, i read david's comment somewhere that `bind()` is automatically called when we call `RegionBootStrap`. And yeah, i can detect altBeacon signals. But I don't know why it's not working for eddystone UID format. – driftking9987 Nov 15 '15 at 12:19
0

The code looks good to me. Make sure that your beacon is actually transmitting an Eddystone-UID frame. Can you try the Beacon Locate app from the Google Play Store? It is based on the same library and uses a similar code snippet to that shown in the question. I use that app with similar code to successfully detect Eddystone-UID beacons.

If that doesn't work, please turn on low level debugging in your app by calling mBeaconManager.setDebug(true) and paste the output of LogCat that looks something like:

D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 0201061aff4c0002153d9d4c66fb0f11e3ab64c82a143314d68079186cb61c09426c756542617220426561636f6e20383833333134453537383038000000

This will tell us the bytes the beacon is actually transmitting so we can see if it is in an Eddystone-UID format.

EDIT: The problem appears to have been a bug in the version of the Android Beacon Library that was bundled with the reference app until November 15, 2015. Please see my other answer for details.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Am using Beacon Locate app for testing purpose. If I make a basic RangingActivity(Your sample only) `public void onResume() { super.onResume(); mBeaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext()); // Detect the main Eddystone-UID frame: mBeaconManager.getBeaconParsers().add(new BeaconParser(). setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19")); mBeaconManager.bind(this); }`,I am able to detect eddystone uid.. (1/2) – driftking9987 Nov 16 '15 at 18:40
  • But If I use https://github.com/AltBeacon/android-beacon-library-reference , only adding `beaconManager.getBeaconParsers().clear(); beaconManager.getBeaconParsers().add(new BeaconParser(). setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));` in the onCreate function, leaving every other thing as it is, just for testing purpose, am not getting any eddystone UID.. My main issue is why am not able to detect eddystone? Please tell your opinion. Thanks. – driftking9987 Nov 16 '15 at 18:43
  • I see the problem. Please see my other answer. – davidgyoung Nov 16 '15 at 21:20
0

There was a bug in version 2.6 of the Android Beacon Library used in the reference application as of November 15, 2015. That bug prevented detection of Eddystone beacons using the default Region specification with three null identifiers.

That bug was fixed as in version 2.6.1 of the library. I upgraded the reference application to use version 2.7 on November 16, 2015 which includes that bug fix.

The simple solution is to use the latest copy of the reference application, or modify the copy you have to change the line from:

compile 'org.altbeacon:android-beacon-library:2.6@aar'

to

compile 'org.altbeacon:android-beacon-library:2.7@aar'
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Thanks. Now am able to detect the eddystone UID. Thanks for fixing the bug but can you please elaborate on what was exactly the problem? Out of those three identifier,one can be used to detect specific beacons, does the update affects that? Thanks a lot. – driftking9987 Nov 17 '15 at 04:59
  • With the bug, `Region` did match a `Beacon` if it had fewer identifiers. The default wildcard region has three null identifiers, and Eddystone-UID only 2. A description of the change is in the first bullet point of the 2.6.1 release notes: https://github.com/AltBeacon/android-beacon-library/releases/tag/2.6.1 This is the commit that fixed the bug: https://github.com/AltBeacon/android-beacon-library/commit/2b6b27c0eb4a1589cdffb3981fe550af1e7e6c23 And this is the commit that created the bug: https://github.com/AltBeacon/android-beacon-library/commit/341be1449743da6137b552d1e9e9544774f1c30 – davidgyoung Nov 17 '15 at 05:44