Not detecting incoming bluetooth connection

  • Replies:3
Rafael Pinto
  • Forum posts: 2

Sep 27, 2011, 2:23:59 AM via Website

Hi,

I am developing a bit with bluetooth, unfortunately my application don't detecting incoming connections. Here's my code:

1private class AcceptThread extends Thread {
2 private final BluetoothServerSocket mmServerSocket;
3
4 public AcceptThread() {
5 // Use a temporary object that is later assigned to mmServerSocket,
6 // because mmServerSocket is final
7 BluetoothServerSocket tmp = null;
8 try {
9 // MY_UUID is the app's UUID string, also used by the client code
10 tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
11 } catch (IOException e) { }
12 mmServerSocket = tmp;
13 }
14
15 public void run() {
16 BluetoothSocket socket = null;
17 // Keep listening until exception occurs or a socket is returned
18 while (true) {
19 try {
20 socket = mmServerSocket.accept();
21 } catch (IOException e) {
22 break;
23 }
24 // If a connection was accepted
25 if (socket != null) {
26 // Do work to manage the connection (in a separate thread)
27 manageConnectedSocket(socket);
28 mmServerSocket.close();
29 break;
30 }
31 }
32 }
33
34 /** Will cancel the listening socket, and cause the thread to finish */
35 public void cancel() {
36 try {
37 mmServerSocket.close();
38 } catch (IOException e) { }
39 }
40}

it blocks on "socket = mmServerSocket.accept();".
I am using the following UUID:
private static final UUID MY_UUID = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");

the SDP name can be arbitrary according to the documentation.

I have tried to transfer files between my computer and my android phone and between my nokia symbian phone and my android phone and always i receive data by default and not with my program.

Can someone help me out ?

Reply
Fabien Röhlinger
  • Admin
  • Staff
  • Forum posts: 3,855

Sep 27, 2011, 11:28:40 AM via Website

Hi, I've pushed this to our other forums as well. Let's see if someone can help.

Reply
Rafael Pinto
  • Forum posts: 2

Sep 28, 2011, 9:17:09 PM via Website

Thank you for your help

I found out that you are from germany.
Dann könnten wir uns ja auf Deutsch unterhalten. :grin:

I found out what my problem was. I changed the uuid to 00001101-0000-1000-8000-00805F9B34FB and it worked.

Reply
Reza SkySoul
  • Forum posts: 1

Dec 20, 2011, 7:32:17 PM via Website

Rafael Pinto
Thank you for your help

I found out that you are from germany.
Dann könnten wir uns ja auf Deutsch unterhalten. :grin:

I found out what my problem was. I changed the uuid to 00001101-0000-1000-8000-00805F9B34FB and it worked.

Hi rafael.... I am so interesting about your script..
Could U send me the application ??
I am also looked at the market and didn't find it..
Thanks in advanced..

Reply