Vérification de la taille des données
This commit is contained in:
parent
0496165464
commit
baa15ceda3
1 changed files with 3 additions and 2 deletions
|
@ -147,9 +147,10 @@ public class BluetoothLeService extends Service {
|
||||||
// For all other profiles, writes the data formatted in HEX.
|
// For all other profiles, writes the data formatted in HEX.
|
||||||
final byte[] data = characteristic.getValue();
|
final byte[] data = characteristic.getValue();
|
||||||
if (data != null && data.length > 0) {
|
if (data != null && data.length > 0) {
|
||||||
if (SampleGattAttributes.SENSOR_CHARACTERISTIC_UUID.equals(characteristic.getUuid())) {
|
if (SampleGattAttributes.SENSOR_CHARACTERISTIC_UUID.equals(characteristic.getUuid())
|
||||||
|
&& data.length >= 1) {
|
||||||
int value = (data[0]<<8)&0x0000ff00 | (data[1]<<0)&0x000000ff;
|
int value = (data[0]<<8)&0x0000ff00 | (data[1]<<0)&0x000000ff;
|
||||||
intent.putExtra(EXTRA_DATA, String.format("%d", value));
|
intent.putExtra(EXTRA_DATA, String.format("décimal: %d", value));
|
||||||
} else {
|
} else {
|
||||||
final StringBuilder stringBuilder = new StringBuilder(data.length);
|
final StringBuilder stringBuilder = new StringBuilder(data.length);
|
||||||
//stringBuilder.append(String.format("%d", data));/
|
//stringBuilder.append(String.format("%d", data));/
|
||||||
|
|
Loading…
Reference in a new issue