0

I tried to read beacon scanresult, some values came but result.getScanRecord().getServiceUuids() always null.

And also i dont understand that how can i parse "result.getScanRecord().getBytes()". i saw many example but it is not understandable or so complex. i need minor, major and uuid values.

I'am using minSdkVersion 21.

1 Answer 1

0

Finally I found something, maybe you need too;

firstly, you need parse to data;

private String[] myFormula(byte[] data) {
    String[] newData = new String[data.length];

    for (int i = 0; i < data.length; i++) {
        if (data[i] > 0) {
            if (Integer.parseInt(data[i] + "", 16) < 9) {
                newData[i] = "0" + Integer.toHexString(data[i]);
            } else {
                newData[i] = Integer.toHexString(data[i]);
            }
        } else {
            newData[i] = Integer.toHexString(data[i] + 256);
        }
    }

    return newData;
}

after you get other datas;

public int getTxPower() {
    Number xx = hexToDec(scanRecord[26]);

    return xx.intValue();
    //return Integer.parseInt(scanRecord[26], 16);
}

public int getMinor() {
    String s = "";
    if (!scanRecord[24].equals("100")) {
        s += scanRecord[24];
    }

    s += scanRecord[25];

    try {
        return Integer.parseInt(s, 16);
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return -1;
    }
}

public int getMajor() {
    String s = "";
    if (!scanRecord[22].equals("100")) {
        s += scanRecord[22];
    }

    s += scanRecord[23];

    try {
        return Integer.parseInt(s, 16);
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return -1;
    }
}

public void get allDatas(){
    scanRecord = myFormula(result.getScanRecord().getBytes());

    MINOR = getMinor();
    MAJOR = getMajor();
    TXPOWER = getTxPower();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.