Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altbeacon library not working on Android 5.0

Yesterday I got the update for Android 5.0 on my Nexus 4, and the altbeacon library stopped detecting beacons. It appears that didEnterRegion and didRangeBeaconsInRegion are not even getting called when monitoring and ranging, respectively.

Even the Locate app from Radius Networks behaves differently now, the values from beacons, once they are detected, doesn't get updated anymore and often it appears as if the beacons went out of range.

One thing I noted differently, is that now in the logcat it appears the following line "BluetoothLeScanner﹕ could not find callback wrapper". I went ahead and looked for that class and saw that it was introduced with Android L, but I don't know if that has something to do with it.

It's important to say that before the update I had been working with both the Locate app and the Reference Application without any trouble.

I don't know if this is a generalized problem or not, but if it happened to me I'm sure it could happen to someone else, so any help it would really be appreciated.

Thanks in advance!

UPDATE:

After failing at getting the library to work I decided to try the Android L branch of the library. What I did was that I plugged in the new library into the Reference App, but didn't work as expected either.

The Monitor Activity seems to be working ok by notifying when the device has entered a new region. However, the Ranging Activity doesn't report any beacons, although didRangeBeaconsInRegion is getting called, always report zero beacons. Curiously, when the activity is paused (switching momentarily to another app) the logcat shows that now didRangeBeaconsInRegion does get called with actual beacons.

I'm kind of stuck right now because I don't know how to get any of libraries working on Android L, so again, any help would really be appreciated.

like image 923
marp Avatar asked Nov 18 '14 17:11

marp


1 Answers

I'm using the latest Altbeacon build on 5.0+ and have no problem with it. in fact, I never used it on kitkat so i'm not really sure i can help but here is my working code which listen to iBeacons.

implement beaconConsumer:

public class MainActivity implements BeaconConsumer

init BeaconManager

        beaconManager = BeaconManager.getInstanceForApplication(this);
        if (beaconManager != null && !beaconManager.isBound(this)) {
        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);
    }

onConnect and start listner

            @Override
public void onBeaconServiceConnect() {
    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            if (beacons.size() > 0) {
                Beacon firstBeacon = beacons.iterator().next();

            }
        } 
     });
    beaconManager.startRangingBeaconsInRegion(new Region("com.example.app", null, null, null));
}

this code is working on 3 devices

  1. Nexus 4 5.0.1
  2. Samsung Galaxy s4 - Stock 5.0.1
  3. Samsung Galaxy s4 - CM12 5.1.1
like image 193
doubleorseven Avatar answered Nov 09 '22 02:11

doubleorseven