【发布时间】:2015-06-13 23:41:45
【问题描述】:
我要说的第一件事是,这是我第一次使用信标。 我正在使用库AltBeacon
目前我有几件事在工作,例如,当我进入一个区域或离开它时.. 也能正确获得到信标的距离。 这完美地工作。 我也得到了 UUID,major 和 minor .. 但不知道我做的是否正确。
这是我的代码:
public class Hello extends Activity implements BeaconConsumer {
protected static final String TAG = "readme";
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hola);
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
}
@Override
public void onBeaconServiceConnect() {
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", Identifier.parse("MY_UUID"), Identifier.parse("1"), null));
} catch (RemoteException e) {
}
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.");
Log.i(TAG, "Reading…"+"\n"+"proximityUuid:"+" "+ beacons.iterator().next().getId1()+"\n"+
"major:"+" "+beacons.iterator().next().getId2()+"\n"+
"minor:"+" "+beacons.iterator().next().getId3());}
}
});
beaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an beacon for the first time!");
}
@Override
public void didExitRegion(Region region) {
Log.i(TAG, "I no longer see an beacon");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "I have just switched from seeing/not seeing beacons: " + state);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
} catch (RemoteException e) {
}
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
}
正如我所说,我得到了 UUID,主要和次要,但我开始使用
beaconManager.setRangeNotifier (new RangeNotifier () {...
setRangeNotifier获取到信标的距离,使其每隔几秒自动更新一次,为此,每次更新时再次获取UUID,major和minor..
这是获取 UUID、主要和次要的正确位置吗? 当我进入一个区域时,我试图得到它:
@Override
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an beacon for the first time!");
}
……但没有成功。
我搜索了很多信息,但找不到任何具体的信息。 我的意图是有一个包含 UUID 的变量,另一个包含主要的变量,另一个包含次要的变量。对吗?
如果这不是正确的方法,那是什么? 和我现在一样正确吗?
我非常感谢任何帮助并提及@davidgyoung ...我希望不要打扰。
您好。
【问题讨论】:
标签: android uuid ibeacon-android altbeacon