标签: simblee

从Android到蓝牙实时流式传输数据的最佳做法

我有一个Android应用程序,将数据写入simblee蓝牙.

在我的代码下面:

public void sendData(String data) {
    Utils.addLog(TAG,"sending data : " + data);
    if (mSerialCharacterstic == null) {
        Utils.addLog(TAG,"serial characteristic not found yet!");
        return;
    }

    Utils.addLog(TAG,"starting write data...");
    mSerialCharacterstic.setValue(data);
    Utils.addLog(TAG,"writing : " + data);
//        mGatt.beginReliableWrite();
        mGatt.writeCharacteristic(mSerialCharacterstic);
    }
Run Code Online (Sandbox Code Playgroud)

/*******************/

    @Override
    public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {

            Utils.addLog(TAG,"onCharacteristicWrite : " + new String(characteristic.getValue()) + " status : " + status);

//            gatt.executeReliableWrite();

    Utils.addLog(TAG,"data written");
    super.onCharacteristicWrite(gatt, characteristic, status);
}
Run Code Online (Sandbox Code Playgroud)

一切正常,(可靠的写作由于某种原因不起作用,但那是另一个问题)

现在,如果我想要流数据(例如onTouch事件实时发送led灯)

与我合作的唯一解决方案是将数据保存到arraylist中,然后OnCharacteriticWrite发送下一个要发送的数据.

        @Override
        public void onCharacteristicWrite(BluetoothGatt gatt, …
Run Code Online (Sandbox Code Playgroud)

android bluetooth stream simblee

10
推荐指数
0
解决办法
368
查看次数

标签 统计

android ×1

bluetooth ×1

simblee ×1

stream ×1