Android BTLE -> Cannot find callback wrapper
Asked Answered
R

4

14

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
Rabon answered 13/5, 2016 at 0:25 Comment(2)
Do you change "myRangingUniqueId" to your beacon's UUID?Boughten
Indeed, I was forgetting to request Core Location permission. PROBLEM SOLVEDRabon
S
9

Be careful not to take lines you see in LogCat too seriously if they are not from your own code. This is especially true if the line starts with "D/", which indicates a debug line, not an error ("E/") I have built dozens of beacon apps, have seen that line more times than I can count, and can confidently say that it does not indicate a problem.

Bottom line: you can safely ignore that message. Be aware that the Android Bluetooth stack is notoriously noisy in LogCat. This will not be the first line you learn to ignore.

Schematize answered 13/5, 2016 at 0:35 Comment(5)
Well, then I cannot figure out why I am detecting 0 beacons. Thought this might be the reason.Rabon
I just started to get the "STATE_ON" and "could not find callback wrapper" logs as well, since then my app couldnt detect beacons anymore (worked before). I'm using Samsung S6 6.0.1 and didn't change a thing. Might be connected to code.google.com/p/android/issues/detail?id=191831#c64 The same app still works on other phones. Strange thing: the Beaconmanager app from beaconinside still detects beacons.Heisser
So "could not find callback wrapper" can be safely ignored?Ubangishari
Yes. See a more detailed answer here: https://mcmap.net/q/798003/-bluetoothlescanner-could-not-find-callback-wrapperSchematize
The more important thing to check is that you are note getting a call to onScanFailed(). If you are, you need to investigate why.Schematize
S
11

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.

Stockstill answered 14/12, 2016 at 18:43 Comment(1)
~"Most likely it is telling you that your device has location permissions turned off". Not true in my case.Ubangishari
S
9

Be careful not to take lines you see in LogCat too seriously if they are not from your own code. This is especially true if the line starts with "D/", which indicates a debug line, not an error ("E/") I have built dozens of beacon apps, have seen that line more times than I can count, and can confidently say that it does not indicate a problem.

Bottom line: you can safely ignore that message. Be aware that the Android Bluetooth stack is notoriously noisy in LogCat. This will not be the first line you learn to ignore.

Schematize answered 13/5, 2016 at 0:35 Comment(5)
Well, then I cannot figure out why I am detecting 0 beacons. Thought this might be the reason.Rabon
I just started to get the "STATE_ON" and "could not find callback wrapper" logs as well, since then my app couldnt detect beacons anymore (worked before). I'm using Samsung S6 6.0.1 and didn't change a thing. Might be connected to code.google.com/p/android/issues/detail?id=191831#c64 The same app still works on other phones. Strange thing: the Beaconmanager app from beaconinside still detects beacons.Heisser
So "could not find callback wrapper" can be safely ignored?Ubangishari
Yes. See a more detailed answer here: https://mcmap.net/q/798003/-bluetoothlescanner-could-not-find-callback-wrapperSchematize
The more important thing to check is that you are note getting a call to onScanFailed(). If you are, you need to investigate why.Schematize
A
0

Not sure whether someone tweaked the code in the last 4 years as BluetoothLeScanner suggests different things than posted answers.

It turns out that an improper call to stopScan() is the culprit. If the wrapper implementation around the passed in ScanCallback parameter is null, BluetoothLeScanner prints this log message and returns without stopping the scan. I reckon it should be logged as an error (Log.e) instead of a Debug log.

I was able to get rid of it by making sure only to call stopScan(callback) if startScan(callback) is previously called.

Aguilera answered 5/6, 2020 at 15:1 Comment(0)
M
0

As a lot of people said, this message can often be safely ignored. However, I ran into a similar issue as you - sometimes, I was detecting 0 BLE devices using BluetoothLeScanner.

Looking through the Debug output in Logcat produced by the BluetoothLeScanner class, I saw that whenever zero devices were detected, onScannerRegistered() - status=6 scannerId=-1 mScannerId=0. Normally, for reference, the output was onScannerRegistered() - status=0 scannerId=10 mScannerId=0.

Looking through various Github repos, I found that this set of outputs correspond to the fact that Android BLE does not support stopping/starting scans more than 5 times in 30 seconds. Log messages like these can often be safely ignored, but it's always good to look at the documentation to check for any info it reveals. Perhaps not in this code snippet, but it is an issue I expect you'll run into working with BLE.

Mauricio answered 10/7, 2021 at 4:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.