Altbeacon显示主要&次要

时间:2016-08-01 10:46:55

标签: android ibeacon-android altbeacon

当我们想要使用此代码获得次要和主要时,我们在两者中都得到null,但在日志中我们得到了值:

当我们想要使用此代码获得次要和主要时,我们在两者中都得到null,但在日志中我们得到值:

        Beacon firstBeacon = beacons.iterator().next();
        Log.i(TAG,"The first beacon " + firstBeacon.toString() + " is about " + firstBeacon.getDistance() + " meters away.");
        Log.i(TAG, "The first beacon I see has minor id "+beacons.iterator().next().getId3());
        Log.i(TAG, "The first beacon I see has major id "+beacons.iterator().next().getId2());

        String minor = beacons.iterator().next().getId3();
        String major = beacons.iterator().next().getId2();

1 个答案:

答案 0 :(得分:2)

你可以尝试

ArrayList<Beacon> mylist = new ArrayList<Beacon>(beacons);
for (int j = 0; j < mylist.size(); j++) {
String rangedUUID = mylist.get(j).getId1().toString();
String rangedMajor = mylist.get(j).getId2().toString();
String rangedMinor = mylist.get(j).getId3().toString();
}

或者您可以替换此

String minor = beacons.iterator().next().getId3();
String major = beacons.iterator().next().getId2();

String minor = firstBeacon.getId3();
String major = firstBeacon.getId2();

<强>由于

beacons.iterator().next()

给下一个灯塔