I'm working on a project where I try to send any file from my phone to my PC. I made the following steps and they all work well:
- Find out available device to connect
- Pairing the Bluetooth device
- Connecting to PC using BluetoothSocket.
The problem happens when I try to write byte[]
to PC using BluetoothOutputStream
.
InputStream fis = null;
OutputStream os = null;
if (isConnected && toSend != null) {
try {
fis = new FileInputStream(toSend);
os = socket.getOutputStream();
byte[] buf = new byte[2048];
if(socket.isConnected()){
while ((fis.read(buf)) != -1) {
os.write(buf);
}
os.flush();
Log.i("tag", "write complete");
}
Log.i("tag", "socket is not yet connected");
} catch (IOException e) {
e.printStackTrace();
}
When it gets to os.write()
, a
ioexcoption: broken pipe
is shown in eclipse logcat and I receive nothing on my PC.
Does anyone know how to handle this problem? I figure that my PC is the cause.