Note that there are some explanatory texts on larger screens.

plurals
  1. POBluetooth file transfer Android
    primarykey
    data
    text
    <p>I am facing a problem in sending large files over bluetooth sockets. Smaller files get transferred correctly. I believe upto 161280 bytes get transferred correctly. </p> <p><strong>EDIT:</strong> I did some more testing and narrowed down the cause. It seems that </p> <pre><code>outStream.write(mybytearray, 0, mybytearray.length); </code></pre> <p>in the sending code part is NOT writing more than 161280 bytes. I saw this behavior by not closing the socket connection, thereby causing the <code>read</code> in the receiving part to "block" on 161280 bytes. What is wrong with the bluetooth output stream here? What am I doing wrong?</p> <p><strong>EDIT 2:</strong> Doing this lets it through.</p> <pre><code>for(int i = 0 ; i &lt; mybytearray.length ; i++){ outStream.write(mybytearray[i]); } </code></pre> <p><strong>Sending code:</strong></p> <pre><code> try { outStream = mBluetoothSocket.getOutputStream(); Log.d(TAG,"outStream created success!"); } catch (IOException e) { Log.d(TAG, "ON RESUME: Output stream creation failed.", e); } File myFile = new File(file_name); Log.d(TAG,"file /source.pdf created success!"); byte[] mybytearray = new byte[(int)myFile.length()]; Log.d(TAG,"file length() =" + (int)myFile.length()); FileInputStream fis = new FileInputStream(myFile); Log.d(TAG,"fis created"); BufferedInputStream bis = new BufferedInputStream(fis,1272254 ); Log.d(TAG,"bis created success"); bis.read(mybytearray,0,mybytearray.length); Log.d(TAG,"ALL Bytes read from bis"); outStream.write(mybytearray, 0, mybytearray.length); Log.d(TAG,"BYTES WRITTEN to OUTSTREAM of socket"); outStream.flush(); Log.d(TAG,"bytes flushed"); outStream.close(); </code></pre> <p><strong>Receiving code:</strong></p> <pre><code>// Attach the i/p stream to the socket try { InputStream in = socket.getInputStream(); mIn = in; Log.d(TAG, "input stream acquired"); } catch (IOException e1) { e1.printStackTrace(); } // Create output streams &amp; write to file FileOutputStream fos = new FileOutputStream( Environment.getExternalStorageDirectory() + "/copy.pdf"); try { bytesRead = mIn.read(buffer, 0, buffer.length); Log.d(TAG, "bytesRead first time =" + bytesRead); current = bytesRead; do { Log.d(TAG, "do-while -- current: " + current); bytesRead = mIn.read(buffer, current, buffer.length - current); Log.d(TAG, "bytesRead: =" + bytesRead); if (bytesRead &gt;= 0) current += bytesRead; } while (bytesRead &gt; -1); } catch (IOException e) { e.printStackTrace(); Log.d(TAG, "do while end:-- buffer len= " + buffer.length + " current: " + current); fos.write(buffer); Log.d(TAG, "fos.write success! buffer: " + buffer.length + " current: " + current); fos.flush(); fos.close(); } } socket.close(); </code></pre> <p><strong>Logcat:</strong></p> <pre><code>D/ReceiveService( 5761): do-while -- current: 155232 D/ReceiveService( 5761): bytesRead: =1008 D/ReceiveService( 5761): do-while -- current: 156240 D/ReceiveService( 5761): bytesRead: =1008 D/ReceiveService( 5761): do-while -- current: 157248 D/ReceiveService( 5761): bytesRead: =1008 D/ReceiveService( 5761): do-while -- current: 158256 D/ReceiveService( 5761): bytesRead: =1008 D/ReceiveService( 5761): do-while -- current: 159264 D/ReceiveService( 5761): bytesRead: =1008 D/ReceiveService( 5761): do-while -- current: 160272 D/ReceiveService( 5761): bytesRead: =1008 D/ReceiveService( 5761): do-while -- current: 161280 W/System.err( 5761): java.io.IOException: Software caused connection abort W/System.err( 5761): at android.bluetooth.BluetoothSocket.readNative(Native Method) W/System.err( 5761): at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:307) W/System.err( 5761): at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96) W/System.err( 5761): at com.bt.server.ReceiveService$AcceptThread.run(ReceiveService.java:141) </code></pre> <p>I am using Motorola Milestone. Android 2.1</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload