Wie kann ich Daten über eine Bluetooth Low Energy (BLE) -Verbindung senden?

Ich bin in der Lage zu entdecken, eine Verbindung zu Bluetooth herzustellen.

Quellcode---

Verbindung über Bluetooth zum Remote-Gerät:

//Get the device by its serial number
 bdDevice = mBluetoothAdapter.getRemoteDevice(blackBox);

 //for ble connection
 bdDevice.connectGatt(getApplicationContext(), true, mGattCallback);

Gatt CallBack für Status:

 private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    //Connection established
    if (status == BluetoothGatt.GATT_SUCCESS
        && newState == BluetoothProfile.STATE_CONNECTED) {

        //Discover services
        gatt.discoverServices();

    } else if (status == BluetoothGatt.GATT_SUCCESS
        && newState == BluetoothProfile.STATE_DISCONNECTED) {

        //Handle a disconnect event

    }
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {

    //Now we can start reading/writing characteristics

    }
};

Jetzt möchte ich Befehle an das Remote BLE-Gerät senden, weiß aber nicht, wie das geht.

Sobald der Befehl an das BLE-Gerät gesendet wurde, sendet das BLE-Gerät Broadcast-Daten, die meine Anwendung empfangen kann.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage