java - 特征 setValue 上的蓝牙 LE Java 字节数组大小

标签 java android bluetooth bluetooth-lowenergy

我正在尝试通过以下代码行在 Android 手机上使用蓝牙 LE 发送值。

我收到一个错误,它超出了数组的大小,由于 0xEA 字节,数组的大小为 127。我将字节转换为 234 左右。有没有办法使用以下代码行发送该字节?

private void writeCharacteristic(BluetoothGatt gatt) 
     {BluetoothGattCharacteristic characteristic;
      Log.d(TAG, "Writing Data");
       characteristic = gatt.getService(SERVICE).getCharacteristic(DATA_IN);
       characteristic.setValue(new byte[]{0x08, 0x01, 0x03, 0x04, 0x52, 0x00, 0x02, 0x62, 0xEA});

       gatt.writeCharacteristic(characteristic);
    }

最佳答案

为了能够在 java 中使用大于 127 的字节值,请使用 (byte)0xEA

关于java - 特征 setValue 上的蓝牙 LE Java 字节数组大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30224600/

相关文章:

java - 在不使用 DefaultTableCellRenderer 的情况下设置 JTable 列水平对齐

来自数据库的 Android SimpleCursorAdapter ID

android - 在 Android Marshmallow 中请求多个蓝牙权限

android - 使用蓝牙的室内定位系统,无需额外设备(例如 ibeacon)

ios - 通过蓝牙将 iPhone 应用程序连接到 PC 应用程序

java - 偶数的平均值返回错误的值

java - 斯卡拉 : class[T] extends T?

java - 为分离的 ListAdapter Android 创建自定义数组适配器

android - 将监听器添加到单个 ListPreference 项目

android - ReceiverRestrictedContext 无法转换为 android.app.Activity