I have a working ble device with android . it sends and receives data finely through the Android app. But Now My Problem is I want to send Some Audio HEX files to my BLE Device. And its larger Than 20 bytes. How Can i send such a data to a BLE Device. ??
For send data upper than 20bytes, you need to change the MTU-exchange.
To API LEVEL 21, you can use requestMtu (Android Developer), it negotiates with the peripherical device and you can define until 512 bytes.
The MTU value is defined in peripherical side. Remember the data size that you can send is MTU-3 bytes.
For API LEVEL less than 21, the MTU is pre-defined and you can't modify.
The size limit can be different than 20, I suppose the MTU size is negotiable, thus you should never hard code any assumptions on sizes.
to get it right, firstly inside the onCharacteristicReadRequest you simple check the offset and give all data from that point to the response.
then in onDescriptorWriteRequest, if the preparedWrite is set to true, you need to store the values you get, and combine them once you get onExecuteWrite() called.
Example implementation available at: https://github.com/DrJukka/BLETestStuff/blob/master/MyBLETest/app/src/main/java/org/thaliproject/p2p/mybletest/BLEAdvertiserLollipop.java
One way you could proceed is to split the audio hex in to small pieces of data .You can use Serial Port Profile to send these chunks of data .Once all data are received you can combine and store using some merging algorithm (google it) and later revert it back to an audio hex file .
来源:https://stackoverflow.com/questions/31404998/how-to-send-an-audio-hex-file-to-ble-device