从UUID读取蓝牙LE阵列?

时间:2016-06-07 20:39:52

标签: android arrays android-studio bluetooth bluetooth-lowenergy

我正在尝试从蓝牙LE设备发送给我的阵列中读取数据。

数据流应为18个字节,当作为数组查看时,我需要字节5,6和7.

我有servicecharacteristic的正确UUID。但是,我无法弄清楚如何从characteristic获取数组。

现在我只是想获取我认识的数据。但是,下面的日志语句会产生我无法理解或与数据匹配的随机字符。

此函数中唯一非常重要的行是characteristic.getValue()的日志,但我想我会将整个内容包含在一些上下文中。

 @Override
        public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
            Log.d(TAG, "characteristic read: "+characteristic.getValue());
            gatt.setCharacteristicNotification(characteristic, true);
            gatt.readRemoteRssi();
            runOnUiThread(update_UI);

            try {
                Thread.sleep(500);
            } catch(InterruptedException ex) {
                Thread.currentThread().interrupt();
            }

            gatt.discoverServices();
        }

1 个答案:

答案 0 :(得分:0)

在数组末尾添加所需字节的括号,可以得到我想要的数据。

Log.d(TAG, "characteristic read: "+characteristic.getValue()[4]);会给我第四个字节。