I'm using the standard example provided here, except I modified it to log that if nothing is found to make sure it's actually called.
@Override
public void onBeaconServiceConnect() {
beaconManager.addRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() == 0) {
Log.i("ActivityMain", "no beacons found");
}
if (beacons.size() > 0) {
Log.i("ActivityMain", "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();
}
}
I have tried adding several additional parsers before binding and I have tried scanning without adding them:
beaconManager.getBeaconParsers().add(new BeaconParser(BeaconParser.ALTBEACON_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser(BeaconParser.EDDYSTONE_TLM_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser(BeaconParser.EDDYSTONE_UID_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser(BeaconParser.EDDYSTONE_URL_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser(BeaconParser.URI_BEACON_LAYOUT));
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);
I have specified the following permissions in the manifest:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
And there are multiple beacons in my room right now, both Eddystone and iBeacon. None of them are found after calling startRangingBeaconsInRegion(...)
D/BluetoothLeScanner: could not find callback wrapper
shows up in logcat quite a lot, if that is any indicator. The thing is the callback seems to be found, because I know for sure that this piece of code
if (beacons.size() == 0) {
Log.i("ActivityMain", "no beacons found");
}
is being executed once a second. I've tried this app Beacon Scanner which also uses AltBeacon and finds my beacons just fine. I've checked its source and it doesn't like there's anything going on that I'm not doing myself, albeit the other app is using kotlin and I'm using java.
I've tried doing this on both a Moto G3 and Galaxy S7 and had no luck with either of them.
What could be the cause of this?