0

I'm trying to get the bootstrap to gather id2 and id3 from iBeacons and start an activity with them. The problem is that the application wouldn't start from the intent and I keep seeing D/BeaconService﹕ Calling ranging callback D/Callback﹕ attempting callback via intent: ComponentInfo{com.rp_ds.chequeplease/org.altbeacon.beacon.BeaconIntentProcessor}

Below is my code:

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "App started up");
    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.setDebug(true);
    // Add AltBeacons Parser for iBeacon
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    // wake up the app when any beacon is seen (you can specify specific id filers in the parameters below)
    region = new Region("com.rp_ds.chequeplease.bootstrapRegion", Identifier.parse("F8EFB5C2-9FFF-47AE-8C8D-D23C417882D1"), null, null);
    regionBootstrap = new RegionBootstrap(this, region);
    backgroundPowerSaver = new BackgroundPowerSaver(this);
    _appPrefs = new AppPreferences(this);
}

@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
    // Don't care
}



@Override
public void didEnterRegion(Region arg0) {
    Log.d(TAG, "Got a didEnterRegion call");
    try {
        beaconManager.startRangingBeaconsInRegion(arg0);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    // This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched)
    // if you want the Activity to launch every single time beacons come into view, remove this call.
}

@Override
public void didExitRegion(Region arg0) {
    // Don't care
}

@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
    Log.d(TAG, "Got a didRangeBeaconsInRegion call");
    for(Beacon beacon:beacons) {
            if(null!=beacon.getId2()&&null!=beacon.getId3()) {
                Intent intent = new Intent(this, MainActivity.class);
                _appPrefs.setRestaurantID(beacon.getId2().toInt());
                _appPrefs.setTableNumber(beacon.getId3().toInt());
                // IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances
                // created when a user launches the activity manually and it gets launched from here.
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                this.startActivity(intent);
                Log.i(TAG,"Application started");
                try {
                    beaconManager.stopRangingBeaconsInRegion(region);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
    }
}

}

I do get a didEnterRegion call but there wasn't a didRangeBeaconsInRegion call. The beacons are also recognized.

D/BeaconParser﹕ This is a recognized beacon advertisement -- 0215 seen
D/BeaconIntentProcessor﹕ got an intent to process
D/RangingData﹕ parsing RangingData
D/RangingData﹕ parsing RangingData
D/BeaconIntentProcessor﹕ got ranging data
D/BeaconIntentProcessor﹕ but ranging notifier is null, so we're dropping it.
odell
  • 3
  • 2
  • Do you ever see the debug line "Got a didEnterRegion call"? Try adding a debug line to the top of `didRangeBeaconsInRegion` and see if you get that, too. – davidgyoung Nov 25 '14 at 11:31
  • Also, please look for any log lines that read like below and add them to your answer if you see them (or report if you do not see them): `D/BeaconParser( 1772): This is a recognized beacon advertisement -- beac seen` – davidgyoung Nov 25 '14 at 11:45
  • @davidgyoung I do get a didEnterRegion call but there wasn't a didRangeBeaconsInRegion call. Wonder if the logs I've provided would help. Could it be because of the ranging notifier being null? – odell Nov 26 '14 at 01:26
  • Yes, that is it. See my answer with code snippet. – davidgyoung Nov 26 '14 at 10:50

1 Answers1

0

The range notifier needs to be set like this:

@Override
public void didEnterRegion(Region arg0) {
    Log.d(TAG, "Got a didEnterRegion call");
    try {
        beaconManager.startRangingBeaconsInRegion(arg0);
        beaconManager.setRangeNotifier(this);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

Make sure the containing class implements the RangeNotifier interface.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204