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 RFCOM开发者_如何学编程M 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
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.
精彩评论