Android BTLE -> Cannot find callback wrapper

user3916570 picture user3916570 · May 13, 2016 · Viewed 11.4k times · Source

I am using Android Beacon Library in my app and I copied, word for word, their example for ranging but I keep getting the error you see below the code. Any help would be greatly appreciated, I am just now getting into BTLE/beacons

package com.example.josh.beacons;

import android.os.Bundle;
import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.RangeNotifier;
import org.altbeacon.beacon.Region;

import java.util.Collection;

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.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
        beaconManager.bind(this);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        beaconManager.unbind(this);
    }
    @Override
    public void onBeaconServiceConnect() {
        beaconManager.setRangeNotifier(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("myRangingUniqueId", null, null, null));
        } catch (RemoteException e) {    }
    }
}

Errors I get:

05-12 20:21:44.769 25775-25775/com.example.josh.beacons D/BluetoothAdapter: STATE_ON
05-12 20:21:44.770 25775-25775/com.example.josh.beacons D/BluetoothLeScanner: could not find callback wrapper
05-12 20:21:44.787 25775-26783/com.example.josh.beacons D/RangingActivity: didRangeBeacons 0

Answer

slund picture slund · Dec 14, 2016

While you can, as the excepted answer says, safely ignore this message, it is telling you something. Most likely it is telling you that your device has location permissions turned off for your app which is preventing your beacon scanning from working. If the app has proper permissions and is properly scanning you will see something more like

D/BluetoothAdapter: STATE_ON
D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5

If you are targeting API level 23+, even if your minsdk is set lower (like 16), you definitely want to check in your code for location permissions being enabled.

I lost many hours to this before realizing it was just silent failing due to location services being turned off for the app.