Android:通过BLE发送大于20个字节的数据

通过连接到外部BLE设备,我最多可以发送20个字节的数据。如何发送大于20个字节的数据。我已经读到我们必须将数据分段或将特征拆分为所需的部分。如果我假设我的数据是32字节,您能否告诉我我需要在代码中进行的更改才能使其正常工作?以下是我的代码中必需的摘录:


public boolean send(byte[] data) {

    if (mBluetoothGatt == null || mBluetoothGattService == null) {

        Log.w(TAG, "BluetoothGatt not initialized");

        return false;

    }


    BluetoothGattCharacteristic characteristic =

            mBluetoothGattService.getCharacteristic(UUID_SEND);


    if (characteristic == null) {

        Log.w(TAG, "Send characteristic not found");

        return false;

    }


    characteristic.setValue(data);

    characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);

    return mBluetoothGatt.writeCharacteristic(characteristic);

}

这是我用于发送数据的代码。在以下onclick事件中使用“发送”功能。


sendValueButton = (Button) findViewById(R.id.sendValue);

    sendValueButton.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View v) {

            String text = dataEdit.getText().toString();                           

            yableeService.send(text.getBytes());

        }

    });

当String text大于20个字节时,则仅接收前20个字节。如何纠正呢?


为了测试发送多个特征,我尝试了以下操作:


sendValueButton = (Button) findViewById(R.id.sendValue);

sendValueButton.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {

        String text = "Test1";                           

        yableeService.send(text.getBytes());


        text = "Test2";                           

        yableeService.send(text.getBytes());


        text = "Test3";                           

        yableeService.send(text.getBytes());

    }

});

但是我只收到“ Test3”,即最后一个特征。我犯了什么错误?我是BLE的新手,请忽略任何幼稚


编辑:


在为以后查看此内容的任何人接受答案之后。


有两种方法可以完成此操作。1.拆分数据并像所选答案一样循环编写。2.拆分数据并使用回调(即)进行写入onCharacterisitcWrite()。如果在编写过程中出现任何错误,这将使您免于错误。


但是,如果您只是在写而不等待固件的响应,则两次写之间最重要的是使用a Thread.sleep(200)。这将确保您的所有数据都能到达。没有sleepI,我总是得到最后一个数据包。如果您注意到已接受的答案,他也会sleep在两者之间使用。


拉莫斯之舞
浏览 2916回答 3
3回答

噜噜哒

BLE最多允许您传输20个字节。如果要发送20个以上的字节,则应定义数组byte[]以包含所需的数据包数量。如果您要发送少于160个字符(160个字节),以下示例可以很好地工作。p / s:根据需要编辑以下内容。不要完全跟随我。实际上,当我们使用BLE时,移动端和固件端需要设置密钥(例如0x03...)来定义双方之间的连接门。这个想法是:当我们继续传输数据包时,不是最后一个。门是byte[1] = 0x01。如果我们发送最后一个,则门为byte[1] = 0x00。数据构造(20字节):1-- Byte 1定义Gate ID:例如。消息门ID byte[0] = 0x03。2- Byte 2定义recognization:是最后一个数据包0x00还是继续发送数据包0x01。3- Byte 3(在消除Byte 1&后,应为18个字节Byte 2)-在此处附加消息内容。在阅读下面的代码之前,请先了解我的逻辑。下面是发送带有许多数据包的消息的示例,每个数据包都是一个大小为20字节的数组。private void sendMessage(BluetoothGattCharacteristic characteristic, String CHARACTERS){&nbsp; &nbsp; &nbsp; &nbsp; byte[] initial_packet = new byte[3];&nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Indicate byte&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; initial_packet[0] = BLE.INITIAL_MESSAGE_PACKET;&nbsp; &nbsp; &nbsp; &nbsp; if (Long.valueOf(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String.valueOf(CHARACTERS.length() + initial_packet.length))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; > BLE.DEFAULT_BYTES_VIA_BLE) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendingContinuePacket(characteristic, initial_packet, CHARACTERS);&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendingLastPacket(characteristic, initial_packet, CHARACTERS);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }private void sendingContinuePacket(BluetoothGattCharacteristic characteristic,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] initial_packet, String CHARACTERS){&nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* TODO If data length > Default data can sent via BLE : 20 bytes&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; // Check the data length is large how many times with Default Data (BLE)&nbsp; &nbsp; &nbsp; &nbsp; int times = Byte.valueOf(String.valueOf(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHARACTERS.length() / BLE.DEFAULT_BYTES_IN_CONTINUE_PACKET));&nbsp; &nbsp; &nbsp; &nbsp; Log.i(TAG, "CHARACTERS.length() " + CHARACTERS.length());&nbsp; &nbsp; &nbsp; &nbsp; Log.i(TAG, "times " + times);&nbsp; &nbsp; &nbsp; &nbsp; // TODO&nbsp; &nbsp; &nbsp; &nbsp; // 100 : Success&nbsp; &nbsp; &nbsp; &nbsp; // 101 : Error&nbsp; &nbsp; &nbsp; &nbsp; byte[] sending_continue_hex = new byte[BLE.DEFAULT_BYTES_IN_CONTINUE_PACKET];&nbsp; &nbsp; &nbsp; &nbsp; for (int time = 0; time <= times; time++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Wait second before sending continue packet&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.sleep(200);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (InterruptedException e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (time == times) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.i(TAG, "LAST PACKET ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* If you do not have enough characters to send continue packet,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* This is the last packet that will be sent to the band&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Packet length byte :&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Length of last packet&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int character_length = CHARACTERS.length()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - BLE.DEFAULT_BYTES_IN_CONTINUE_PACKET*times;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initial_packet[1] = Byte.valueOf(String.valueOf(character_length&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + BLE.INITIAL_MESSAGE_PACKET_LENGTH));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initial_packet[2] = BLE.SENDING_LAST_PACKET;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.i(TAG, "character_length " + character_length);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Message&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Hex file&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] sending_last_hex = new byte[character_length];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Hex file : Get next bytes&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < sending_last_hex.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sending_last_hex[i] =&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHARACTERS.getBytes()[sending_continue_hex.length*time + i];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Merge byte[]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] last_packet =&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new byte[character_length + BLE.INITIAL_MESSAGE_PACKET_LENGTH];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.arraycopy(initial_packet, 0, last_packet,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, initial_packet.length);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.arraycopy(sending_last_hex, 0, last_packet,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initial_packet.length, sending_last_hex.length);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set value for characteristic&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; characteristic.setValue(last_packet);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.i(TAG, "CONTINUE PACKET ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* If you have enough characters to send continue packet,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* This is the continue packet that will be sent to the band&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Packet length byte&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int character_length = sending_continue_hex.length;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* TODO Default Length : 20 Bytes&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initial_packet[1] = Byte.valueOf(String.valueOf(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; character_length + BLE.INITIAL_MESSAGE_PACKET_LENGTH));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* If sent data length > 20 bytes (Default : BLE allow send 20 bytes one time)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* -> set 01 : continue sending next packet&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* else or if after sent until data length < 20 bytes&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* -> set 00 : last packet&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initial_packet[2] = BLE.SENDING_CONTINUE_PACKET;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Message&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Hex file : Get first 17 bytes&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < sending_continue_hex.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.i(TAG, "Send stt : "&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + (sending_continue_hex.length*time + i));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Get next bytes&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sending_continue_hex[i] =&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHARACTERS.getBytes()[sending_continue_hex.length*time + i];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Merge byte[]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] sending_continue_packet =&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new byte[character_length + BLE.INITIAL_MESSAGE_PACKET_LENGTH];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.arraycopy(initial_packet, 0, sending_continue_packet,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, initial_packet.length);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.arraycopy(sending_continue_hex, 0, sending_continue_packet,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initial_packet.length, sending_continue_hex.length);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set value for characteristic&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; characteristic.setValue(sending_continue_packet);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write characteristic via BLE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mBluetoothGatt.writeCharacteristic(characteristic);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String data) {&nbsp; &nbsp; &nbsp; &nbsp; if (mBluetoothAdapter == null || mBluetoothGatt == null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.w(TAG, "BluetoothAdapter not initialized");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if (ActivityBLEController.IS_FIRST_TIME) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* In the first time,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* should send the Title&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] merge_title = sendTitle(data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set value for characteristic&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; characteristic.setValue(merge_title);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write characteristic via BLE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mBluetoothGatt.writeCharacteristic(characteristic);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Reset&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ActivityBLEController.IS_FIRST_TIME = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* In the second time,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* should send the Message&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (data.length() <= BLE.LIMIT_CHARACTERS) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendMessage(characteristic, data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Reset&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ActivityBLEController.IS_FIRST_TIME = true;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Typed character&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; typed_character = data.length();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }

慕码人8056858

在Lollipop上,您最多可以发送512字节。您需要使用 BluetoothGatt.requestMtu()512的值。此外,正如@Devunwired提到的那样,您需要等到之前的任何操作完成后才能调用此函数。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
Android