How can i uniquely identify an iBeacon using android ALT Beacon library?

986 views Asked by At

I have made my iphone 4s an iBeacon and able to detect this using Locate Beacon app from my Glaxy S4, 5.01, I have also detected this using beacon reference library by modifying its layout found from this question. Its showing the detect beacon in device logs from the library files as below,

onScanResult() - ScanResult{mDevice=6C:64:80:68:86:59, mScanRecord=ScanRecord [mAdvertiseFlags=26, mServiceUuids=null, mManufacturerSpecificData={76=[2, 21, -96, -54, 104, -88, 101, -76, 75, 30, -66, -91, 73, -91, -114, -5, -124, 29, 0, 0, 0, 0, -59]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=null], mRssi=-46, mTimestampNanos=162979288294680}

i am getting device name always null, and also unable to get the uuid, and i can't get that in my application, can any one please help how can i get beacon info in my application ?

Also How can i uniquely identify a beacon?

Here's what i have done so far, downloaded a ALT beacon library, then ALT beacon library reference, added library dependency, and written the following code in Ranging Activity class,

modified the onCreate method as

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ranging);
    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.getBeaconParsers().add(new BeaconParser().
              setBeaconLayout("m:0-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));  // iBeacons
    beaconManager.bind(this);

}

and implements this by BeaconConsumer, and added his method as

@Override
public void onBeaconServiceConnect() {
    // TODO Auto-generated method stub
    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override 
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            if (beacons.size() > 0) {
                Log.i(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");        
            }
        }
    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
    } catch (RemoteException e) {  e.printStackTrace();  }
}

if i run the code without,

beaconManager.getBeaconParsers().add(new BeaconParser().
              setBeaconLayout("m:0-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));  // iBeacons

then it works fine when add this statement get exception as mentioned before.

2

There are 2 answers

0
arslan haktic On BEST ANSWER

Finally i am able to identify my problem, my beacon parser was wrong

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

i was using this while i correct results that detects an ibeacon for me are given by this parser

beaconManager.getBeaconParsers().add(new BeaconParser(). setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
12
davidgyoung On

It sounds like you are using beacon Monitoring when you really want to be using beacon Ranging. Monitoring is used to tell you when any one of a group of beacons with shared identifier parts (or any beacon at all) is first detected. But it doesn't tell you the exact identifiers of the beacons in view.

In order to read the identifiers of beacons that are visible at a given time, you should use the Ranging APIs. These APIs give you a callback to your code once per second with a list of all visible beacons matching the Region you define.

@Override 
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
     for (Beacon beacon: beacons) {
        Log.i(TAG, "I see a beacon with identifiers: "+beacon.getId1()+" "+beacon.getId2()+" "+beacon.getId3());        
     }
}

See the Ranging Example Code on this page for more details on how to set this up.