I want to take the byte value out of this class so I can parse it, or if it's possible parse it inside and get the 5th and 6th byte value out.
private void broadcastUpdate(final String action,
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
// This is special handling for the Heart Rate Measurement profile. Data parsing is
// carried out as per profile specifications:
// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
final byte[] data = characteristic.getValue();
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format("%02X", byteChar));
intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
} else {
// For all other profiles, writes the data formatted in HEX.
}
}
sendBroadcast(intent);
}
How this works is that I step on a scale and it sends me these bytes:
00 00 00 00 02 02 00 00 00 00 00 00 00 00 00 00
Which is stored at the variable 'data'. How do I take 'data' out to use in another class?
The weight data is on bytes 5 and 6. If you convert the hex values of bytes 5 and 6, in that example is '0202
' it becomes 514 in decimal (51.4kg).
I need to take the bytes data to use in another class to get the kg data. How would I go around doing so?