我想扫描我周围的任何一种信标。基本上,如果我理解正确的话,你需要在扫描之前知道他们的身份?你如何扫描你周围的任何信标,提取它们的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所以问题是,我如何在不事先知道身份的情况下探测到这些信标?
发布于 2016-02-01 13:56:39
两点:
Region定义本质上是一个通配符,它将匹配所有信标标识符,因此您不需要预先了解它们。所显示的代码已经有了以下内容。在这一行之后:
beaconManager.startRangingBeaconsInRegion(new Region("myRegion", null, null, null));添加以下内容:
beaconManager.startMonitoringBeaconsInRegion(new Region("myRegion", null, null, null));https://stackoverflow.com/questions/35131806
复制相似问题