Rafael Pinto
- Forum posts: 2
Sep 27, 2011, 2:23:59 AM via Website
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:
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 ?
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}
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 ?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.