0
votes

I'm working on a simple beacon proximity app using AltBeacon library from here https://altbeacon.github.io/android-beacon-library/samples.html.

I am experimenting with the sample code provided on the above website, however, each time I run the app it only goes to addRangingNotifier() method. If it detected the beacon it would go log the beacon size.

private Region defaultRegion = null;
defaultRegion = new Region("BeaconIdentifier", Identifier.fromUuid(java.util.UUID.fromString(UUID)), null, null);
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);

@Override
public void onBeaconServiceConnect() {
   beaconManager.addRangeNotifier(new RangeNotifier() {
      @Override
      public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
         if (beacons.size() > 0) {
            Log.d("MainInfo","Beacon List Size " + beacons.size());
         }else{
            Log.d("MainInfo","Beacon Empty");
         }
      }
   });
   try {
      beaconManager.startRangingBeaconsInRegion(defaultRegion);
   } catch (RemoteException e) {}
}

I can receive the beacon size around of me.
I test the two device(A : Samsung galaxy J510-Marshmellow/B: Samsung galaxy J7-Nougat), B scan the beacon and print Beacon List Size, but, A can't scan the beacon and print Beacon Empty.

So I test same Marshmellow device, but I can't find it.

Are there any codes that should be added depending on the operating system?

1
Maybe worth checking that if the location permission is granted to the app on the phone?Ricky Mo
@RickyMo Of course thatPolaris Nation
Did this solve the problem?davidgyoung
@davidgyoung yes. when I change dependencies { implementation 'org.altbeacon:android-beacon-library:2+' } to AAR file (in project structure and import aar file), it show the scan result. So now I can scan. Thank you for your answerPolaris Nation

1 Answers

1
votes

The most likely thing wrong is that the UUID specified does not match your beacon. Try replacing this code:

  Identifier.fromUuid(java.util.UUID.fromString(UUID))

With

  null

To match all beacons. If this fixes it, replace the UUID with the one you are out of the detected beacon.