Altbeacon didRangeBeaconsInRegion не вызывается на Samsung S9 (Android 8) - PullRequest
0 голосов
/ 26 октября 2018

Я пробовал на других телефонах, таких как Huawei Mate 10 Pro (Android 8.0), Nexus 5 и LeEco LePro3 с Android 6, и он работает безупречно. Но для моего Samsung я не получаю данные маяка. didRangeBeaconsInRegion даже не вызывается.

Это мой инициал:

   //initialization of the beacon manager
public void initBeaconManager(Context context, BeaconConsumer beaconConsumer) {
    beaconManager = BeaconManager.getInstanceForApplication(context);
    setNeededTypesOfBeacons();
    beaconManager.bind(beaconConsumer);
}

  //sets the types of beacons that the library is searching for
public void setNeededTypesOfBeacons() {
    beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
    beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT));
    beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
    beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout(BeaconParser.ALTBEACON_LAYOUT));
    beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.getBeaconParsers().add(new BeaconParser()
            .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
}

Вот как я могу подключиться к своему менеджеру маяков:

   //will try to reconect beacon manager, or call the onBeaconServiceConnect
public void reconnectBeaconManager(BeaconConsumer beaconConsumer) {
    Log.i("BluetoothService", "BluetoothService reconnectBeaconManager");
    if (beaconManager.isBound(beaconConsumer)) {
        Log.i("BluetoothService", "BluetoothService reconnectBeaconManager BOUND==================");
        //TODO will have to take the saved beacons, and use those.
        PSApplicationClass.getInstance().onBeaconServiceConnect();
    } else {
        Log.i("BluetoothService", "BluetoothService reconnectBeaconManager UNBOUND==================");
        beaconManager.bind(beaconConsumer);
        PSApplicationClass.getInstance().onBeaconServiceConnect();
    }
}

  //this function will be called after it connects to the beacon service
public void onBeaconServiceConnect(RangeNotifier rangeNotifier) {
    Log.i("BluetoothService", "BluetoothService onBeaconServiceConnect listen for beacons: " + listenForBeacons + " / beacon uuid: " + beaconUUID);
    PSBluetoothService.getInstance(context).startListeningForBeacons(rangeNotifier);
}

 //will start listening to beacons
public void startListeningForBeacons(RangeNotifier rangeNotifier) {
    try {
        Region region = new Region("all-beacons-region", null, null, null);
        // Tells the BeaconService to start looking for beacons that match the passed Region object
        beaconManager.startRangingBeaconsInRegion(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    // Specifies a class that should be called each time the BeaconService gets ranging data, once per second by default
    beaconManager.addRangeNotifier(rangeNotifier);
}

Это метод didRangeBeaconsInRegion, который не вызывается:

   @Override
public void didRangeBeaconsInRegion(final Collection<Beacon> beacons, Region region) {
    Log.i("BluetoothService", "!!!!!!!!!!!!!!!!!!!!!!! BluetoothService didRangeBeaconsInRegion");
    if (beacons.size() > 0) {
        Log.i("BluetoothService", "!!!!!!!!!!!!!!!!!!!!!!! BluetoothService region The first beacon I see is about " + beacons.iterator().next().getDistance() + " meters away.");
        if (didRangeBeaconsCallback != null)
            didRangeBeaconsCallback.rangeCalled(beacons, region);
    } else {
        Log.i("BluetoothService", "!!!!!!!!!!!!!!!!!!!! BluetoothService region NO BEACONS: " + beacons.size());
        if (didRangeBeaconsCallback != null)
            didRangeBeaconsCallback.rangeCalled(null, null);
    }
}

Почему я получаю inRange для других телефонов, а не для Samsung, как я могу это исправить? Я что-то не так делаю?

У них есть задание на github: https://github.com/AltBeacon/android-beacon-library/issues/756 Но, пожалуйста, дайте мне знать, если существует обходной путь, пока они не исправят

...