views:

208

answers:

1

Hey guys,

does someone know how to receive a file on android via RFCOMM? I'm a newby to bluetooth issues, so please have patience with me.

I'm looking for an approach to receive data via RFCOMM as a stream and store it somewhere on my phone. Saving data is not the problem, it works quite fine.

The main issue is the implementation of the connection and the reliable retrieval of the data...

This whole procedure should be implemented as an android service (so that no activity has to be launched while receiving data). What would you suggest: Local or remote service?

greetz, poeschlorn

+1  A: 

In General:

  • Establish the Bluetooth socket
  • Open the input and output streams
  • (Transport layer) negotiate the transfer if necessary, file name, attributes
  • Start transferring the data bytes and saving them to file

The transport layer is the key, and the tricky part. It can be as simple as rolling your own. For example:

Sender sends: [Start of stream] | FILENAME | ATTRIBUTES | [binary data] [End Of stream]

Receiver sees the file name and attributes, saves them, and opens up an output file and starts writing from after attributes, to the end of the stream.

After the transfer is complete, close the input/output streams, and then close the socket.

Brad Hein
hey, thanks for your answer, I know I'm late. This scheme seems to work similar to the sample bluetooth chat from google, with sending a file in the stream. Do you know weather this is SPP (Serial Port Profile)?
poeschlorn
Right - SPP (aka RFCOMM) is the stream type supported by Android but RFCOMM offers you a binary stream between two devices, which is perfect for transferring files.
Brad Hein