0

I use this code luugiathuy.com/2011/02/android-java-bluetooth/
The server side is the PC
the client is the device, with the app based on bluetooth chat example

The device (galaxy tab 7.0) can establish connection with the PC. However the PC server (written in java and bluecove) did nothing, as nothing is connected.

The loop for trying to find connected device is

while(true) {
        try {
            System.out.println("waiting for connection...");
            connection = notifier.acceptAndOpen();

            Thread processThread = new Thread(new ProcessConnectionThread(connection));

            processThread.start();

        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

Output on PC: uuid: 0000110100001000800000805f9b34fb waiting for connection... EDIT: source downloadhttps://github.com/luugiathuy/Remote-Bluetooth-Android

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
RadZaeem
  • 311
  • 2
  • 4
  • 11

3 Answers3

1

Same issue I got when I was trying in linux. But the reason (still not sure) when you run the bluetooth android application without turning on the Java server using bluecove, It will try to connect with the already installed bluetooth software. You may see the bluetooth icon asking for granting access to the mobile device.

To solve this, I just changed the uuid in the server and application (say from 1103 to 1101 and vice versa) and then started the server first and then the android application. Java server part started listening.

The reason I think may be the uuid when it did not found the bluecove stack service server, it got connected to the device server listening on same uuid. So after changing the uuid and making sure that the server is running before launching the android application should solve the issue.

If you are getting connected to the bluetooth system application and not to the Java bluecove server,

1) First change the uuid both server and android application.
2) Second make sure your server is running and listening on same uuid.
3) Launch the android application which try to communicate on same rfcomm connection uuid.

Server part code I took from : http://www.jsr82.com/jsr-82-sample-spp-server-and-client/ Library : http://code.google.com/p/bluecove/downloads/list

Jeet
  • 761
  • 3
  • 10
  • 27
0

Yes, it happens with me too, I suggest you to fire following commend on shell, when it shows waiting for connection.

hcitool cc 58:C3:8B:D7:FA:F4

here 58:C3:8B:D7:FA:F4 is my device's bluetooth address, which should be replaced by your device's bluetooth address.

To get your device's bluetooth address, just start bluetooth in your device with discoverable mode and execute hcitool scan command, it will display all the active device with their name and bluetooth address.

Well you may run the above hcitool cc 58:C3:8B:D7:FA:F4 command via Java code as follows,

try
{
     Process p=Runtime.getRuntime().exec("hcitool cc 58:C3:8B:D7:FA:F4"); 
}
catch ( Exception e )
{

}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • I am not sure, but on windows, you dont require that command. are you running on windows ? – Lucifer Aug 31 '12 at 04:05
  • @RadZaeem, do you have antivirus/windows firewall enabled on pc ? try disabling it. It also blocks such bluetooth connections. – Lucifer Aug 31 '12 at 04:21
  • tried disabling, still cannot get it working. anyway i tried a remote bluetooth app from playstore, it works flawless even without disabling antivirus/firewall – RadZaeem Aug 31 '12 at 04:31
0

The output from your program says it listens on UUID 0x1101. Is that true? The sample you reference shows it listening on a different UUID. Its Service Class Id is 0x04c6093b and is set as follows:

34  UUID uuid = new UUID(80087355); // "04c6093b-0000-1000-8000-00805f9b34fb"
35  String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
36  notifier = (StreamConnectionNotifier)Connector.open(url); 

The two need to match on client and server.

alanjmcf
  • 3,430
  • 1
  • 17
  • 14