title: Android Bluetooth Increase Speed Performance
body: <p>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). </p>
  
  <p>How does the "Share" function differ from using the Bluetooth API? How can I replicate the "Share" method to get optimized transfer speed?</p>
  
  <p>Thanks,</p>
  
  <p>Bluetooth API test code:</p>
  
  <p>Server side - installed on one android device</p>
  
  <pre><code>BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  mServerSocket = mBluetoothAdapter.listenUsingRfcommWithServiceRecord("DeviceName", MY_UUID);
  socket = mServerSocket.accept();
  mInStream = socket.getInputStream();
  int totalByte = 1;
  while (totalByte &lt; 2718720) 
  {
      int bytesAvailable = mInStream.available();
      if (bytesAvailable &gt; 0) {
          totalByte += bytesAvailable;
          byte[] buffer = new byte[bytesAvailable];
          mInStream.read(buffer);
      }
  }
  </code></pre>
  
  <p>Client side - installed on other android device</p>
  
  <pre><code>mClientSocket = device.createInsecureRfcommSocketToServiceRecord(
                  MY_UUID);
  mClientSocket.connect();
  mOutStream = mClientSocket.getOutputStream();
  byte byteValue = 0;
  for (int i=0; i&lt;2718720; i++) {
      byteValue++;
      mOutStream.write(byteValue);
  }
  </code></pre>