1: Business scenario: The Bluetooth device sends more than 20 bytes, but the mobile phone cannot receive the data. The hardware does not send packets, which is a bit strange. No data exceeding 20 bytes can be received. This is an underlying limitation of Android.
* Android 底层貌似做了限制只能接受20个字节 * There are four basic operations for moving data in BLE: read, write, notify, and indicate. * The BLE protocol specification requires that the maximum data payload size for these * operations is 20 bytes, or in the case of read operations, 22 bytes. * BLE is built for low power consumption, for infrequent short-burst data transmissions. * Sending lots of data is possible, but usually ends up being less efficient than classic * Bluetooth when trying to achieve maximum throughput. */
1. The hardware sends more than 20 bytes in packets. This is a more reasonable approach. The client is grouping the packets.
2. The hardware does not subpackage and sends more than 20 bytes at a time. This seems to be no more than 512 bytes, as agreed by both parties.
Two: Let me show you a picture.
Three: Solution
/** * Change the default maximum length of a single packet sent and received by BLE, for android 5.0 and above * @param mtu * @return */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static boolean requestMtu(int mtu ){ //The size of the configuration data I configured is 512 if (mBluetoothGatt != null) { return mBluetoothGatt.requestMtu(mtu); } return false; }
This method is called after the Bluetooth connection is successful
Summarize:
After testing, the data can be received. Xiaomi phone 7.0 can receive it. I have not tested other phones.