Improve transfer speed by buffering the reads and writes (in 
pre-allocated fixed sized arrays) and DON'T allocate a new byte buffer in 
the middle of your while loop...

On Tuesday, June 7, 2016 at 3:18:13 AM UTC+10, Devin Chen wrote:
>
>
> I am trying to increase the transfer speed on android bluetooth. I 
> experimented transferring a 2.7MB buffer from one android device to another 
> using RFComm socket of the Bluetooth API (see code below). It took ~70 secs 
> to complete. I compared this method against the "Share" via bluetooth 
> function that came with the phone. The "Share" function gave exceptionally 
> better performance (~15 secs to transfer a 2.7MB file). 
>
> How does the "Share" function differ from using the Bluetooth API? How can 
> I replicate the "Share" method to get optimized transfer speed?
>
> Thanks,
>
> Bluetooth API test code:
>
> Server side - installed on one android device
>
>
> Thanks,
>
> Bluetooth API test code:
>
>
> Server side - installed on one android device
>
>
> BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
> mServerSocket = 
> mBluetoothAdapter.listenUsingRfcommWithServiceRecord("DeviceName", MY_UUID);
> socket = mServerSocket.accept();
> mInStream = socket.getInputStream();int totalByte = 1;while (totalByte < 
> 2718720) {
>     int bytesAvailable = mInStream.available();
>     if (bytesAvailable > 0) {
>         totalByte += bytesAvailable;
>         byte[] buffer = new byte[bytesAvailable];
>         mInStream.read(buffer);
>     }}
>
> Client side - installed on other android device
>
>
> mClientSocket = device.createInsecureRfcommSocketToServiceRecord(
>                 MY_UUID);
> mClientSocket.connect();
> mOutStream = mClientSocket.getOutputStream();byte byteValue = 0;for (int i=0; 
> i<2718720; i++) {
>     byteValue++;
>     mOutStream.write(byteValue);}
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/812ee3a1-09a6-4843-ab18-4a53db402122%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to