Bluetooth 使用同步方法发送消息

Bluetooth 使用同步方法发送消息,bluetooth,message,bluetooth-lowenergy,synchronized,characteristics,Bluetooth,Message,Bluetooth Lowenergy,Synchronized,Characteristics,我需要通过BLE向自定义设备发送消息 我能够发送低于20字节的消息。我只是: public boolean writeCharacteristic(byte[] value){ if (mBluetoothGatt == null) { Log.e(TAG, "lost connection"); return false; } BluetoothGattService Service = mBl

我需要通过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;
    }
但我需要在“尽可能短的时间”内发送更长的消息。我发现:

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

我发现:,但不是每件事对我来说都很清楚


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

我的方法是在您的案例中使用简单的for循环发送数据。在begging上,我们在iOS上尝试了此方法,耗时5秒。我们需要在1-2秒内发送所有消息并收到答复。这就是为什么使用同步方法的想法。