Android OBEX OPUSH Server with bluecove

657 views
Skip to first unread message

tuxGurl

unread,
Sep 30, 2011, 3:35:37 PM9/30/11
to bluecove-developers
Hello,

My android app requires an OBEX Push Server and I've turned to
bluecove because it doesn't seem possible to setup an obex opush
server on the android using the api level 7 (2.1).

I have setup my project with bluecove-2.1.1-SNAPSHOT.jar and bluecove-
android2-2.1.1-20101024.214840-1.jar.

Here is my code snippet:


BlueCoveImpl.setConfigObject(BlueCoveConfigProperties.PROPERTY_ANDROID_CONTEXT,
this);

//A custom uuid that the client device is looking for.
UUID OBEX_OBJECT_PUSH = new
UUID("123456789123456789123456789abcde", false);

final String url = "btgoep://localhost:" + OBEX_OBJECT_PUSH +

";name=myapp;authenticate=false;master=false;encrypt=false;android=true";
final SessionNotifier serverConnection = (SessionNotifier)
Connector.open(url);
final ServiceRecord record =
localDevice.getRecord(serverConnection);
final String recurl =
record.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT,
false);
Log.d(Constant.TAG, TAG + "BT server url: " + recurl);
final int OBJECT_TRANSFER_SERVICE = 0x100000;
try
{
record.setDeviceServiceClasses(OBJECT_TRANSFER_SERVICE);
}
catch (final Throwable e)
{
Log.d(Constant.TAG, TAG + "setDeviceServiceClasses", e);
}

This is the error that I get:
09-30 15:22:37.917: DEBUG/(myapp)(18314): [BluetoothService] BT server
url: null
09-30 15:22:37.927: DEBUG/(myapp)(18314): [BluetoothService]
setDeviceServiceClasses
09-30 15:22:37.927: DEBUG/(myapp)(18314):
com.intel.bluetooth.NotSupportedRuntimeException: Not Supported on
android_2.x
09-30 15:22:37.927: DEBUG/(myapp)(18314): at
com.intel.bluetooth.ServiceRecordImpl.setDeviceServiceClasses(ServiceRecordImpl.java:
551)
09-30 15:22:37.927: DEBUG/(myapp)(18314): at
com.myclient.myapp.client.android.BluetoothObexServer.<init>(BluetoothObexServer.java:
60)
09-30 15:22:37.927: DEBUG/(myapp)(18314): at
com.myclient.myapp.client.android.gui.activity.HomeActivity.onCreate(HomeActivity.java:
63)

What am I missing here? The UUID needs to be specific because the
client is looking for it. Even if I change it to the standard 0x1105 I
get null back from record.getConnectionURL().

Any help is appreciated!!

tuxGurl

unread,
Oct 3, 2011, 10:29:51 AM10/3/11
to bluecove-developers
Ok, so I was out to lunch on some of my assumptions!

Let me rephrase my question. How do I setup an OBEX OPUSH server on a
2.1 or greater android?

I changed the uuuid to: UUID OBEX_OBJECT_PUSH = new UUID(0x1105);
And now I get:
WARN/BluetoothService(1478): Attempted to register a reserved UUID:
00001105-0000-1000-8000-00805f9b34fb
ERROR/(myapp)(4930): java.io.IOException: Not able to register SDP
record for mobileid

Using a linux machine to scan I noticed that the phone already
advertises:
Service Name: OBEX Object Push
Service RecHandle: 0x10007
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 12
"OBEX" (0x0008)
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100

So is my server setup clashing with an inbuilt OBEX server? Now, if
there is an inbuilt server, and this might be out of scope for this
group, how can I use it instead?


Thanks for reading this far!

tuxGurl

Mina Shokry

unread,
Oct 3, 2011, 11:26:22 AM10/3/11
to bluecove-...@googlegroups.com
Hi TuxGirl,

Yes, this means your phone already has an OBEX push server. To use it instead, just discover and connect to it from your other device just normal.
If you mean you want to deal with files received from this service, it is very android specific, may be you can try with the appropriate content provider if you know the type of the received file.

To register your own service, just use a UUID rather than the standard 0x1105 and on the client side, you will have to connect to your new UUID, Unfortunately, there is no way now to declare that your service supports OBEX, but once you declare it with the new UUID and once the client find it, you can do whatever you want including OBEX exchange.

Regards,
Mina.

--
You received this message because you are subscribed to the Google
Groups "bluecove-developers" group.
For more options, visit this group at
http://groups.google.com/group/bluecove-developers

tuxGurl

unread,
Oct 3, 2011, 5:00:19 PM10/3/11
to bluecove-developers
Thanks Mina, that advice gave me a little progress.

Is there anyway that I can specify a channel? Every time my app starts
and registers the service I get a new channel. The device I am
connecting to remembers the channel when pairing the first time. I
don't have access to the client device code.

Ideas?

tuxGurl

unread,
Oct 4, 2011, 10:32:48 AM10/4/11
to bluecove-developers
Hello Mina,

Every time the device sends a file over I get "java.io.IOException:
File descriptor in bad state". The file is a binary file with custom
extension. Am I missing something? My code is below:


UUID OBEX_OBJECT_PUSH = new UUID("xxxx....", false);
SessionNotifier serverConnection = null;
LocalDevice localDevice;

try
{
localDevice = LocalDevice.getLocalDevice();

if (!localDevice.setDiscoverable(DiscoveryAgent.GIAC))
{
Log.e(Constant.TAG, TAG + "Fail to set LocalDevice
Discoverable");
}

final String url = "btgoep://localhost:" +
OBEX_OBJECT_PUSH +

";name=myapp;authenticate=false;master=false;encrypt=false;android=true";

serverConnection = (SessionNotifier) Connector.open(url);

final ServiceRecord record =
localDevice.getRecord(serverConnection);
}
catch (final Throwable e)
{
Log.e(Constant.TAG, TAG + "SERVER Error ", e);
}

int errorCount = 0;
int count = 0;
final boolean isRunning = true;
boolean isStoped = false;

try
{
while (!isStoped)
{
try
{
count++;
serverConnection.acceptAndOpen(this);
}
catch (final InterruptedIOException e)
{
isStoped = true;
break;
}
catch (final Throwable e)
{
if (errorCount > 3)
{
isStoped = true;
}
if (isStoped)
{
return;
}
errorCount++;
Log.e(Constant.TAG, TAG + "acceptAndOpen ", e);
continue;
}
errorCount = 0;
}
}
finally
{
Log.d(Constant.TAG, TAG + "OBEX Server finished!");

Mina Shokry

unread,
Oct 4, 2011, 10:37:45 AM10/4/11
to bluecove-...@googlegroups.com
Sorry, I am not an OBEX expert. But your code looks like OK.

For your previous question about the channel, unfortunately, you can't specify a channel. Bluecove (and implementations at lower layers) select the first available channel.

tuxGurl

unread,
Oct 4, 2011, 11:34:16 AM10/4/11
to bluecove-developers
Thanks for all your help Mina. I really appreciate it!

tuxGurl

unread,
Oct 7, 2011, 4:18:58 PM10/7/11
to bluecove-developers
Hello,

So I was able to get past the fixed channel issue with a devious
workaround.

Taking your advice, I am using the android BluetoothServerSocket to
register my own service with custom UUID and I now get data that looks
like an OBEX connect request: 80 00 07 10 00 04 00 followed by zeros.
Instead of me coding the OBEX protocol is there any way I can hook
into bluecove to handle the connection for me? If not, can you point
me to the core classes that handle OBEX OPUSH protocol? I can dig into
the source and figure out the protocol.

Thanks!

On Oct 3, 11:26 am, Mina Shokry <minasho...@gmail.com> wrote:

Mina Shokry

unread,
Oct 7, 2011, 7:44:24 PM10/7/11
to bluecove-...@googlegroups.com
Of course you can fork bluecove code to do whatever you want to do. You can trace the code inside javax.obex package.
Reply all
Reply to author
Forward
0 new messages