Android BluetoothSocket OutputStream writes blocks endlessly

I need to programmatically write data from 1 to 100 MB in pieces of 1024 bytes to a remote Bluetooth device. Both are Android devices. Here is an example code snippet in my data transfer client program -

bTSocket.connect(); //connect to remote BT device
DataOutputStream outStream = new DataOutputStream(bTSocket.getOutputStream());
byte[] buffer = new byte[1024];
int bytesToTransfer = 1000000;
while (bytesToTransfer > 0) {
    outStream.write(buffer);
    outStream.flush();
    bytesToTransfer -= 1024;
}
outStream.close();

While running this piece of code on Android 2.2 (Froyo), it works great. However, in the case of Android 2.3.4 and 4.0.4, outStream.write (buffer) blocks indefinitely after the transfer of some data (say, 100 KB). It should be noted that the remote device is not configured to listen to data. Is there a limit on the amount of data that can be recorded?

+6
source share
1 answer

Bluetooth .

, , .write(), - , - . " !". , , TCP . Bluetooth .

, Bluetooth . , , . .write() , - . , - .

Android, , , Bluetooth.

+6

All Articles