AltBeacon API возвращает пустую коллекцию при ранжировании маяков

Я пытаюсь ранжировать маяки и делаю именно то, что здесь написано: http://altbeacon.github.io/android-beacon-library/samples.html

Метод didRangeBeaconsInRegion срабатывает, но всегда с пустой коллекцией.

Я установил «locate» с помощью altbeacon и обнаружил 3 маяка.

это мой код: я что-то упустил?

public  class BeaconSingletone implements BeaconConsumer {

    private static BeaconSingletone instance;

    private final org.altbeacon.beacon.BeaconManager beaconManager2;
    private  ArrayList<BeaconThin> listNearBeacons = new ArrayList<>();




    BeaconRegion region = new BeaconRegion("ranged region",
                              UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null);

    private List<EventInterface> listeners = new ArrayList<EventInterface>();

    private BeaconSingletone()
    {

        beaconManager2 = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(ar_activity.get());
        // To detect proprietary beacons, you must add a line like below corresponding to your beacon
        // type.  Do a web search for "setBeaconLayout" to get the proper expression.
         beaconManager2.getBeaconParsers().add(new BeaconParser().
                setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
        beaconManager2.bind(this);



    public static BeaconSingletone getInstance() {
        if(instance == null) {
            instance = new BeaconSingletone();
        }
        return instance;
    }
    private void showNotification(Region region, final List<Beacon> list) {
        listNearBeacons.clear();
        listNearBeacons.add(new BeaconThin(3514,7580,-1));
        for (Iterator<EventInterface> i = listeners.iterator(); i.hasNext(); ) {
            EventInterface item = i.next();
            //item.NewBeaconFound(list.get(0).getMajor(),list.get(0).getMinor(),Utils.computeAccuracy(list.get(0)));
            item.NewBeaconsFound(listNearBeacons);
        }
        return;




    }



    @Override
    public void onBeaconServiceConnect() {
        beaconManager2.addRangeNotifier(new RangeNotifier() {
            @Override
            public void didRangeBeaconsInRegion(Collection<org.altbeacon.beacon.Beacon> beacons, org.altbeacon.beacon.Region region) {
                if (beacons.size() > 0) {
                    Log.i("BeaconManager", "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");
                }
            }
        });
        try {
            beaconManager2.startRangingBeaconsInRegion(new org.altbeacon.beacon.Region("mybeacons", null, null, null));
        } catch (RemoteException e) {    }{


    }

    }

    @Override
    public Context getApplicationContext() {
        return ar_activity.get();
    }

    @Override
    public void unbindService(ServiceConnection serviceConnection) {
        ar_activity.get().unbindService(serviceConnection);
    }

    @Override
    public boolean bindService(Intent intent, ServiceConnection serviceConnection, int i) {
        return ar_activity.get().bindService(intent, serviceConnection, i);
    }
}

person user1032412    schedule 30.01.2018    source источник


Ответы (1)


Вам нужно добавить макет маяка для используемого типа маяка (iBeacon?). Замените эту строку:

beaconManager2.getBeaconParsers().add(новый BeaconParser(). setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d: 25-25"));

С правильным макетом отсюда: https://beaconlayout.wordpress.com

person davidgyoung    schedule 30.01.2018
comment
Да, дело было именно в этом. Мне пришлось изменить его на: m: 2-3 = 0215, i: 4-19, i: 20-21, i: 22-23, p: 24-24, спасибо - person user1032412; 30.01.2018