我正在尝试将我从几个信标接收到的信息解析为一个recyclerview。 recyclerview将我解析的第一个信息加载到onCreate()中。我已经为每个信标专门设置了标识符,因此它在recyclerview的特定位置进行更新。但是由于某种原因,它不会进入函数本身。信标本身没有日志。当我在didRangeBeaconsInRegion()中放置日志时,确实从每个信标中获得了相应的标识符。
有什么提示吗?抱歉,信标还很新。
/**
* Implementation of the beacon Consumer class. Is called when searching for beacons.
*/
@Override
public void onBeaconServiceConnect() {
Log.d(TAG, "onBeaconServiceConnect: beacons connected.");
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
for(Beacon beacon : collection){
String tempString = beacon.getId1().toString();
checkBeacon(tempString, (float)beacon.getDistance());
}
}
});
// Start ranging the beacons
try{
Log.d(TAG, "onBeaconServiceConnect: Start ranging beacons.");
beaconManager.startRangingBeaconsInRegion(new Region("MyRegion",null,null,null));
}catch (Exception e){
e.printStackTrace();
}
}
private void checkBeacon(String ID, float distance){
if(ID == beaconIdentifier[0]){
beacons.set(0, beaconsName[0] + ":" + distance);
Log.d(TAG, "checkBeacon:" + beacons.get(0));
}
if(ID == beaconIdentifier[1]){
beacons.set(1, beaconsName[1] + ":" + distance);
Log.d(TAG, "checkBeacon:" + beacons.get(1));
}
if(ID == beaconIdentifier[2]){
beacons.set(2, beaconsName[2] + ":" + distance);
Log.d(TAG, "checkBeacon:" + beacons.get(2));
}
if(ID == beaconIdentifier[3]){
beacons.set(3, beaconsName[3] + ":" + distance);
Log.d(TAG, "checkBeacon:" + beacons.get(3));
}
}