title: Bluetooth Server Android - Client Java Bluecove. UUID?
body: <p>I'm writing an application to communicate between my smartphone and a computer using a bluetooth device.</p>
  
  <p>I'm using <a href="http://bluecove.org/index.html" rel="nofollow noreferrer">Bluecove</a> to manage the bluetooth on the computer, and the android API for my android device.</p>
  
  <p>However, when I'm debugging, nothing happens. I think that the problem is that the UUID is wrong. I'm not sure how to get the devices to identify each other, in order to establish a connection.</p>
  
  <p>I have read some other "questions" about those tags, but what I've tried didn't fix my problem:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/9164138/simple-bluetooth-data-receiver-android">Simple Bluetooth data receiver Android</a></li>
  <li><a href="https://stackoverflow.com/questions/4949509/android-obtaining-uuid-of-a-bluetooth-device">Android: obtaining uuid of a bluetooth device</a></li>
  <li>Etc...</li>
  </ul>
  
  <p>Here's what I've written so far:</p>
  
  <ol>
  <li><p>For tho android (Server) (This is the function that will make the connection)</p>
  
  <p>public void connectSocket(){
      blueAdapter.cancelDiscovery(); // Cancel discovery because it'll slow down the connection</p>
  
  <pre><code>final BluetoothServerSocket serverSocket;
  BluetoothServerSocket sSocket= null;
  try{
      sSocket = blueAdapter.listenUsingRfcommWithServiceRecord("BluetoothJANE", MY_UUID);
  }catch(IOException e){}
  serverSocket = sSocket;
  
  Thread acceptThread = new Thread(new Runnable() {
  
      @Override
      public void run() {
          BluetoothSocket socket = null;
          while(true){
              try{
                  socket = serverSocket.accept();
              }catch(IOException e){
                  break;
              }
              if(socket != null){
                  try{
                      iStream = socket.getInputStream();
                      oStream = socket.getOutputStream();
                  } catch(IOException e){}
              }
          }
      }
  });
  acceptThread.start();
  </code></pre>
  
  <p>}</p></li>
  <li><p>For java app on PC (This is the constructor of the class (it's on an independent thread) that will manage the bluetooth connection)</p>
  
  <p>public ModuleBluetooth() {</p>
  
  <pre><code>StreamConnectionNotifier notifier = null;
  StreamConnection connection = null;
  
  try {
      blueDevice = LocalDevice.getLocalDevice();
      blueDevice.setDiscoverable(DiscoveryAgent.GIAC);
  
      String url = "btspp://localhost:" + MY_UUID.toString()
              + ";name=RemoteBluetooth";
      notifier = (StreamConnectionNotifier) Connector.open(url);
  
  } catch (BluetoothStateException e) {
      System.out
              .println("ModuleBluetooth: Error getting the bluetooth device");
  } catch (IOException e) {
  }
  System.out.println("waiting for connection...");
  try {
      connection = notifier.acceptAndOpen();
      System.out.println("Conenction created");
  } catch (IOException e) {
      System.out.println("Can not create the connection");
  }
  </code></pre>
  
  <p>}</p></li>
  </ol>
  
  <p>Could somebody please help me? Any thoughts would be very much appreciated.</p>
  
  <p>I have also tried to use some functions to acquire the UUID (in android) such as, [fetchUuidsWithSdp][2] (and the related functions) but eclipse doesn't recognize that functions (It seems that they don't exist in "my" API).</p>
  
  <p><a href="http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#fetchUuidsWithSdp%28%29" rel="nofollow noreferrer">http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#fetchUuidsWithSdp%28%29</a></p>