onBeacon ServiceConnect方法是检测信标。用于棒棒糖版本检测用于牛轧糖和奥利奥版本信标未检测的:public void onBeaconServiceConnect(){
RangeNotifier rangeNotifier = new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, org.altbeacon.beacon.Region region) {
Log.d(TAG, "in didRangeBeaconsInRegion " + beacons.size());
if (beacons.size() > 0) {
Log.d(TAG, "didRangeBeaconsInRegion called with beacon count: " + beacons.size());
for (Iterator<Beacon> iterator = beacons.iterator();
iterator.hasNext(); ) {
Beacon beacon = iterator.next();
if (beaconlist.size() > 0) {
Log.d(TAG, "List Size :" + beaconlist.size());
for (int i = 0; i < beaconlist.size(); i++) {
Log.d("BeaconList ", beaconlist.get(i));
}
}
if (!beaconlist.contains(beacon.getId1().toString())) {
Log.d(TAG,"In get APi");
getApi(beacon.getId1().toString());
beaconlist.add(beacon.getId1().toString());
Log.d(TAG, "Notify in dead state");
Log.d("Notify in dead state", beacon.getId1().toString());
}
}
}
}
};
try {
Log.d(TAG, "I am in startRangingBeaconsInRegion");
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
beaconManager.addRangeNotifier(rangeNotifier);
} catch (RemoteException e) {
e.printStackTrace();
}
}
这是我的代码可以在任何一个给了这个问题的解决方案。
有两件事情要检查:
onBeaconServiceConnect()
?如果不这样做,你会当您尝试启动范围得到一个RemoteException。这是登录此异常与Log.e(TAG, "Not bound to beacon scanning service")
到logcat的一个好主意