1

我需要通过 BLE 向自定义设备发送消息。

我能够发送低于 20 个字节的消息。我只用过:

 public boolean writeCharacteristic(byte[] value){

        if (mBluetoothGatt == null) {
            Log.e(TAG, "lost connection");
            return false;
        }
        BluetoothGattService Service = mBluetoothGatt.getService(UUID_SERVICE_GENERIC_ATTRIBUTE);
        if (Service == null) {
            Log.e(TAG, "service not found!");
            return false;
        }
        BluetoothGattCharacteristic charac = Service.getCharacteristic(UUID_WRITE);
        if (charac == null) {
            Log.e(TAG, "char not found!");
            return false;
        }

        charac.setValue(value);
        boolean status = mBluetoothGatt.writeCharacteristic(charac);
        return status;
    }

但我需要在“尽可能短的时间内”发送更长的消息。我发现: Android:通过 BLE 发送数据 >20 字节

但我需要使用同步方法和 onCharacteristicWrite (这应该是最快的方法)。

我发现: http: //blog.stylingandroid.com/bluetooth-le-part-6/,但对我来说并不是一切都清楚。

您是否有一些简单的示例如何使用同步方法通过 ble 发送消息?

4

0 回答 0