Android AltBeacon不等

时间:2016-02-01 13:30:51

标签: android ibeacon ibeacon-android altbeacon android-ibeacon

我想扫视周围的任何一种灯塔。基本上如果我理解正确,你需要在扫描之前知道他们的身份证明吗?你将如何扫描周围的任何信标并提取他们的UUID /工厂ID /等等?

这是我目前的代码:

public class TestActivity extends Activity implements BeaconConsumer {

private BeaconManager beaconManager;

public static final String TAG = "TestActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startBeaconScan();
}

public void startBeaconScan() {
    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.setDebug(true);
    beaconManager.bind(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.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v"));
    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=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.setMonitorNotifier(new MonitorNotifier() {
        @Override
        public void didEnterRegion(final Region region) {
            Log.d(TAG, "ENTERED REGION: "+region);
        }

        @Override
        public void didExitRegion(Region region) {}

        @Override
        public void didDetermineStateForRegion(int i, Region region) {}
    });
    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
            Log.d(TAG, "BEACONS: "+collection.size());
        }
    });
}

@Override
public void onBeaconServiceConnect() {
    try {
        beaconManager.startMonitoringBeaconsInRegion(new Region("myRegion", null, null, null));
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

}

我在输出中收到这些消息,但没有别的:

beacon detected : id1: f7826da5-4fa1-4e48-8024-bc5b70e0891a id2: 49089 id3: 34388

所以问题是,如何在不事先知道ID的情况下检测这些信标?

1 个答案:

答案 0 :(得分:1)

两点:

  1. 使用所有空标识符创建Region定义本质上是一个匹配所有信标标识符的通配符,因此您无需事先了解它们。显示的代码已经有了这个。

  2. 要获取检测到的信标列表,您需要开始测距。显示的代码有一个raging回调,但它没有开始测距。

  3. 这一行之后:

    beaconManager.startRangingBeaconsInRegion(new Region("myRegion", null, null, null));
    

    添加:

    beaconManager.startMonitoringBeaconsInRegion(new Region("myRegion", null, null, null));
    
相关问题