如何从android beacon读取major,minor

时间:2014-04-23 12:16:12

标签: android bluetooth-lowenergy ibeacon android-bluetooth ibeacon-android

我在android(sticknfind android SDK)中使用了一些sticknfind beacons。如何从源代码中的信标中获取主要和次要值?我使用过该应用程序:StickNFind Beacon Maker,我已经指定了这些值。

Major: 0001 Minor: 0002

为了获得uuid:dev.getBtDevice().getAddress()

没有dev.getBtDevice().getMinor()getMajor()

4 个答案:

答案 0 :(得分:4)

public String getMajor() {
    major = String.valueOf( (mScanRecord[25] & 0xff) * 0x100 + (mScanRecord[26] & 0xff));
    return major;
}

public String getMinor() {
    minor =     String.valueOf( (mScanRecord[27] & 0xff) * 0x100 + (mScanRecord[28] & 0xff));
    return minor;
}

答案 1 :(得分:1)

我不确定您拨打getBtDevice().getAddress()时使用的是什么SDK,但我怀疑这会返回蓝牙MAC地址,而不是您正在寻找的ProximityUUID。这可能就是为什么我们没有相应的方法来获得主要和次要。

幸运的是,如果您的信标已经在传输,那么有一种更简单的方法。只需安装iBeacon Locate应用,然后使用它即可通过无线方式阅读您的标识符。

如果您想以编程方式执行此操作,请查看该应用所基于的Android iBeacon Library

答案 2 :(得分:1)

我使用RadiusNetwork's iBeacon libraryAndroid library):

简单如下:

iBeacon.getProximityUuid()
iBeacon.getMajor()
iBeacon.getMinor()

答案 3 :(得分:0)

使用alt beacon library 2.3.5,将其添加到Build.gradle文件中的app模块:

compile 'org.altbeacon:android-beacon-library:2.3.5'

然后,您可以分别从Beacon类的getId2()getId3()方法中获取major和minor。