質問

I am attempting to retrieve a very large (potentially 2^32 - 1) unsigned 32 bit integer from a bluetooth 4.0 characteristic using the getIntValue method of my BluetoothGattCharacteristic instance.

I am passing FORMAT_UINT32 to getIntValue, but because it returns an Integer it can't return a number larger than 2^31 - 1. When I try getting a value larger than 2^31 - 1 it incorrectly returns a negative integer.

What's the point of getIntValue accepting FORMAT_UINT32 if it can't possibly return an unsigned 32 bit integer? Is there something I am missing?

Is my only option to use getValue() and manually convert it to a long?

役に立ちましたか?

解決

Looks like this works for me:

long value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, 0) & 0x00000000ffffffffL;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top