Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RFCOMM socket on fixed channel

I am writting an android application to talk to a hardware device which is totally outside of my control.

My application creates a listening socket using listenUsingRfcommWithServiceRecord and the UUID 00001101-0000-1000-8000-00805F9B34FB. It then calls accept() on that socket to wait for the remote device to connect, but it never does.

I have spoken to the makers of the hardware device, and they say that their device will "simply connect to channel 1" on the remote device. i.e. it does not do a SDP discovery to find out the correct channel number. They refuse to change this (even though it is of course wrong)

My question is are there any ways to force android to use a fixed RFCOMM channel number? Maybe using reflection, like the trick of directly calling createRfcommSocket when connecting to a client.

like image 632
didster Avatar asked Feb 03 '11 14:02

didster


2 Answers

A very hackey way is to consume all the channels and then release the one you want! I have the same issue as you and this hack is working in the field for about a year with no complaints. There are loopholes to this, so the success will depend on your use case.

There are a max of 30 channels so you will open 30 connections (or less) with a UUID you define. Now, using spdtool find the UUID of socket connection to the channel you want. Close that connection.

Now the channel, 1 in your case, will be the only channel available. Connect to it the way you want. Once the connection is established, close all other connections.

I know it's hackey as hell but it worked for my use-case!

like image 179
tuxGurl Avatar answered Oct 12 '22 00:10

tuxGurl


Those APIs exist, but are not supported. If you are still interested, check out the source code for the source for the Android 1.5 backport of android.bluetooth.

Be warned, though, that as unsupported APIs they can be removed in any future release.

like image 24
Richard Szalay Avatar answered Oct 12 '22 00:10

Richard Szalay