Sending a File Using Bluetooth Obex Object Push Profile (Opp)

Sending file over OBEX push profile

OBEX is specified by the IrDA. Unfortunately they've started to charge for access to the specification documents, http://www.irda.org/displaycommon.cfm?an=1&subarticlenbr=7#OBEX However there are copies of the previous version OBEX13.pdf lying around on various places on the internet...

What's your platform BTW. On .NET (including Compact Framework) there is OBEX support in the 32feet.NET library and full and complete support in the Brecham.Obex library.

http://32feet.codeplex.com/, and Brecham.Obex http://inthehand.com/files/folders/objectexchange/entry6351.aspx

Receive file by Bluetooth via OBEX Object PushProfile

I believe I have (at least a partial) solution which should then allow files to be intercepted via OPP and custom code added. The first step is to go to settings > apps > running > Bluetooth Share and kill the BluetoothOppService

Then I used reflection to access a method on BluetoothAdapter (code below) which allows listening on a specific port. After which we can intercept the incoming OPP communication and interact with the input and output streams. This SO thread will help with the OPP communication part, but as an initial step I read the data stream and reponded with an OPP 'OK' message ie os.writeByte(ObexSession.OBEX_SUCCESS | ObexSession.OBEX_FINAL_BIT);

// simplified exception handling
public class BluetoothAdapterProxy
{
public static final int CHANNEL_OPP = 12;

final BluetoothAdapter target;
static final Class<?> targetClass = BluetoothAdapter.class;
Method listenOn;

public BluetoothAdapterProxy(BluetoothAdapter target)
{
this.target = target;
Class<?>[] args = new Class[] { int.class };
try
{
this.listenOn = targetClass.getDeclaredMethod(
"listenUsingRfcommOn", args);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
}

public BluetoothServerSocket listenUsingRfcommOn(int channel)
{
try
{
return (BluetoothServerSocket) (listenOn.invoke(target,
new Object[] { channel }));
}
catch (Exception e)
{
// complain loud, complain long
throw new RuntimeException(ex);
}
}
}

Usage: initialise using

serverSocket = new BluetoothAdapterProxy(BluetoothAdapter.getDefaultAdapter())
.listenUsingRfcommOn(BluetoothAdapterProxy.CHANNEL_OPP);

After which, use the following from a separate Thread (to prevent blocking) and remote devices can connect via socket = serverSocket.accept();



Related Topics



Leave a reply



Submit