Monday, June 15, 2009

Bluetooth OBEX file sharing in Android

I'd like to use OBEX in Android Dev phone, but there is no any available bluetooth application yet. Therefore, I made some changes from 'openobex' and 'obexpushd', then I can run these applications in Android. According to Android Bluetooth architecture, we can see ‘RFCOMM’ in kernel bluez. RFCOMM is a simple set of transport protocols, made on top of the L2CAP protocol, providing emulated RS-232 serial ports (up to sixty simultaneous connections to a bluetooth device at a time). In the protocol stack, RFCOMM is bound to L2CAP. In Bluetooth, OBEX is used for many profiles that require simple data exchange, e.g. object push, file transfer, basic imaging, basic printing, phonebook access etc. In the protocol stack, OBEX is bound to RFCOMM. It means if I can use RFCOMM connections between two BT devices correctly, I should be able to use OBEX between them.

Here is my experiment!

I prepared two bluetooth devices, one is my ubuntu laptop and the other one is Android Dev Phone. I installed bluez version 4.32 in Ubuntu and bluez version 3.36 in Android. OBEX is like the client-server networking. The sending file one is a client and the receiving one is a server. For example, if I want to receive a file via bluetooth in Android Dev phone, I can run an OBEX data server and it would start to listen a channel for any incoming connections. If I want to send a file via bluetooth in Android Dev phone, I can use obex_test or obexftp to push data to another BT device.

Receiving file in Android Dev phone

> obexpushd -n -d

this command would start an OBEX data server with debug message, not detach from terminal, and the default channel is 9. Be aware of the file permission problem in Android! I run this command in /sdcard folder, and then it can store the incoming files in this folder with write permission.

Sending file from Android Dev phone

> obex_test -b OTHER_BT_ADDR CHANNEL

this command will build the connection betwen Android Dev phone and the other BT device. OTHER_BT_ADDRESS is the other BT device address and CHANNEL is its OBEX channel number.

Done! Listening to the music!

PS. source code is in google code temporally and I will move to gitorious site soon.


  1. THANKS I will chek this in tomorrow seems VERY intresting :-)

  2. Is it possible to package this as userland .apk using the android native development kit ?

  3. i guess no! this OBEX stuff is native C language, not java. BTW, you don't need to use apk to install it. you can just upload binary files to Android Dev phone.

  4. yes, I know it is native stuff here. Just that it seems possible from reading the doc here -, guess need to use JNI to expose services available to the java userland.

  5. umm....i don't know how to use it with Android ndk..:(


Note: Only a member of this blog may post a comment.