Beacons aren't showing Altbeacon

I'm trying to get the code working with the demo code provided by Altbeacon. Normally it should log something but it doesn't. What it does show in logcat is this

01-11 20:50:33.964 12498-12508/com.example.thomas.test1 D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=EF:47:2A:56:1B:55, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0000feaa-0000-1000-8000-00805f9b34fb], mManufacturerSpecificData={29540=[5, -86, -69, -52, -35, -18, -1, 0, 17, 34, 51, 68]}, mServiceData={0000feaa-0000-1000-8000-00805f9b34fb=[16, -30, 0, 103, 111, 111, 103, 108, 101, 0]}, mTxPowerLevel=-30, mDeviceName=Beacon1], mRssi=-26, mTimestampNanos=981220542678629}

So it does detect the beacon but does not show it as a log.

Code i used:

public class MainActivity extends AppCompatActivity implements BeaconConsumer{

protected static final String TAG = "RangingActivity";
private BeaconManager beaconManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    beaconManager = BeaconManager.getInstanceForApplication(this);

    beaconManager.bind(this);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    beaconManager.unbind(this);
}

@Override
public void onBeaconServiceConnect() {
    beaconManager.addRangeNotifier(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("0000feaa-0000-1000-8000-00805f9b34fb", null, null, null));
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

Does anyone know what i did wrong? Thanks in advance!

1 answer

  • answered 2018-01-11 22:02 davidgyoung

    A few things to check:

    1. You need to add beacon parsers for the Eddystone frames you want to detect into the onCreate method.

      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.getBeaconParsers().add(new BeaconParser().
          setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
        beaconManager.getBeaconParsers().add(new BeaconParser().
          setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
        beaconManager.bind(this);
      }
      
    2. Make sure you have requested the proper permissions dynamically, which is required if you are on Android 6+. Instructions for doing this are here: https://altbeacon.github.io/android-beacon-library/requesting_permission.html

    3. Add a log line to the start of onBeaconServiceConnect() to make sure that is getting called.