How to read UDID, Major, Minor of beacon on android devices?

一个人想着一个人 提交于 2019-11-30 17:26:50

问题


I am trying to develop a BLE application for Android.

Is the any way through which i can detect and read UDID, Major, Minor of beacon on android devices?

I have read the RadiusNetworks android-ibeacon-service, but I can't understand why:

major = (256 * (0xFF & paramArrayOfByte[(i + 20)]) +
 (0xFF & paramArrayOfByte[(i + 21)]));

which paramArrayOfByte is LeScanCallback byte[] scanRecord


回答1:


When you get the byte[] scanRecord from BluetoothAdapter.LeScanCallback, it will include the Bluetooth LE headers, which can be variable length depending on the type of iBeacon.

Because of the variable length headers the four bytes that indicate an iBeacon advertisement (4c 00 02 15) may begin anywhere from the third byte (scanRecord[2]) up to the sixth byte (scanRecord[5]). In the latest code, the Android iBeacon Library finds the index position of the 4c 00 02 15 within the scanRecord and calls it the startByte. Everything else is at a fixed position relative to that startByte.




回答2:


  1. scanRecord should be parsed as a list of AD structures.
  2. iBeacon is a kind of AD structures.

With nv-bluetooth, you can extract iBeacon like the following.

public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
{
    // Parse the payload of the advertising packet.
    List<ADStructure> structures =
        ADPayloadParser.getInstance().parse(scanRecord);

    // For each AD structure contained in the advertising packet.
    for (ADStructure structure : structures)
    {
        if (structure instanceof IBeacon)
        {
            // iBeacon was found.
            IBeacon iBeacon = (IBeacon)structure;

            // Proximity UUID, major number, minor number and power.
            UUID uuid = iBeacon.getUUID();
            int major = iBeacon.getMajor();
            int minor = iBeacon.getMinor();
            int power = iBeacon.getPower();

            ........

See "iBeacon as a kind of AD structures" for details.



来源:https://stackoverflow.com/questions/20782532/how-to-read-udid-major-minor-of-beacon-on-android-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!