2010-10-13 12 views
5

Estoy tratando de crear un programa simple que busque un auricular bluetooth (estoy probando con un auricular PS3) y luego me conecto a él. Estoy usando el código del bluetooth chat program example. Sin embargo, no puedo conectarlo a nada. Me está dando una Excepción de E/S cuando llega a connect().Conectar/Par Auriculares Bluetooth y Android

private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 

Este hilo se ejecuta al intentar realizar una conexión saliente con un dispositivo. Corre recto; la conexión tiene éxito o falla.

private class ConnectThread extends Thread { 
    private final BluetoothSocket mmSocket; 
    private final BluetoothDevice mmDevice; 

    public ConnectThread(BluetoothDevice device) { 
     mmDevice = device; 
     BluetoothSocket tmp = null; 

     // Get a BluetoothSocket for a connection with the given BluetoothDevice 
     try { 
      tmp = device.createRfcommSocketToServiceRecord(MY_UUID); 
     } catch (IOException e) { 
      Log.e(TAG, "create() failed", e); 
     } 
     if (tmp == null){ 
      Log.i(TAG, "tmp is NULL"); 
     } 
     mmSocket = tmp; 
    } 

    public void run() { 
     Log.i(TAG, "BEGIN mConnectThread"); 
     setName("ConnectThread"); 

     // Always cancel discovery because it will slow down a connection 
     mAdapter.cancelDiscovery(); 
     Log.i(TAG, "discovery is cancelled"); 

     // Make a connection to the BluetoothSocket 
     try { 
      // This is a blocking call and will only return on a successful connection or an exception 
      mmSocket.connect(); //Doesn't like something here??? 
     } catch (IOException e) { 
      Log.e(TAG, "IO error, ", e); 
      connectionFailed(); 
      // Close the socket 
      try { 
       mmSocket.close(); 
      } catch (IOException e2) { 
       Log.e(TAG, "unable to close() socket during connection failure", e2); 
      } 
      // Start the service over to restart listening mode 
      newTBluetoothService.this.start(); 
      return; 
     } 

     // Reset the ConnectThread because we're done 
     synchronized (newBluetoothService.this) { 
      mConnectThread = null; 
     } 

     // Start the connected thread 
     connected(mmSocket, mmDevice); 
    } 

    public void cancel() { 
     try { 
      mmSocket.close(); 
     } catch (IOException e) { 
      Log.e(TAG, "close() of connect socket failed", e); 
     } 
    } 
} 

Aquí es el Logcat:


10-13 16:07:45.544: ERROR/BluetoothService.cpp(1259): 
stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) 

10-13 16:07:45.544: DEBUG/newBluetoothService(2821): connect to: 00:22:A6:07:12:2B 

10-13 16:07:45.544: DEBUG/newBluetoothService(2821): setState() 0 -> 2 

10-13 16:07:45.552: INFO/newBluetoothService(2821): BEGIN mConnectThread 

10-13 16:07:45.567: ERROR/BluetoothService.cpp(1259): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) 

10-13 16:07:45.567: INFO/newBluetoothService(2821): discovery is cancelled 

10-13 16:07:45.575: ERROR/BluetoothEventLoop.cpp(1259): onCreateDeviceResult: D-Bus error: org.bluez.Error.AlreadyExists (Device already exists) 

10-13 16:07:45.583: INFO/BluetoothNew(2821): MESSAGE_STATE_CHANGE: 2 

10-13 16:07:46.700: ERROR/BluetoothEventLoop.cpp(1259): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/2872/hci0/dev_00_22_A6_07_12_2B 

10-13 16:07:47.036: DEBUG/BluetoothService(1259): updateDeviceServiceChannelCache(00:22:A6:07:12:2B) 

10-13 16:07:47.059: DEBUG/BluetoothService(1259):  uuid(system): 0000111e-0000-1000-8000-00805f9b34fb 1 

10-13 16:07:47.067: DEBUG/BluetoothService(1259):  uuid(system): 00001108-0000-1000-8000-00805f9b34fb 2 

10-13 16:07:47.075: VERBOSE/BluetoothEventRedirector(1786): Received android.bleutooth.device.action.UUID 

10-13 16:07:47.075: DEBUG/BluetoothService(1259): Cleaning up failed UUID channel lookup: 00:22:A6:07:12:2B 00001101-0000-1000-8000-00805f9b34fb 

10-13 16:07:47.083: ERROR/newBluetoothService(2821): IO error, 

10-13 16:07:47.083: ERROR/newBluetoothService(2821): java.io.IOException: Service discovery failed 

10-13 16:07:47.083: ERROR/newBluetoothService(2821):  at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377) 

10-13 16:07:47.083: ERROR/newBluetoothService(2821):  at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201) 

10-13 16:07:47.083: ERROR/newBluetoothService(2821):  at com.nmtransfer.bluetooth.newBluetoothService$ConnectThread.run(newBluetoothService.java:347) 

10-13 16:07:47.083: INFO/newBluetoothService(2821): Connection Failed 

10-13 16:07:47.083: DEBUG/newBluetoothService(2821): setState() 2 -> 1 

10-13 16:07:47.083: DEBUG/newBluetoothService(2821): start 

10-13 16:07:47.083: INFO/BluetoothNew(2821): MESSAGE_STATE_CHANGE: 1 

10-13 16:07:47.098: DEBUG/BluetoothService(1259): new handle 1000d 

10-13 16:07:47.106: DEBUG/newBluetoothService(2821): setState() 1 -> 1 

10-13 16:07:47.106: DEBUG/newBluetoothService(2821): BEGIN mAcceptThreadThread[Thread- 
13,5,main] 

10-13 16:07:47.114: INFO/BluetoothNew(2821): MESSAGE_STATE_CHANGE: 1 

10-13 16:07:51.036: ERROR/BluetoothEventLoop.cpp(1259): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/2872/hci0/dev_00_22_A6_07_12_2B 

10-13 16:07:53.583: VERBOSE/BluetoothEventRedirector(1786): Received android.bleutooth.device.action.UUID 

Cualquier ayuda es muy apreciada.

Gracias Chris

+0

Estoy probando en un Droid X con la actualización 2.2 y un auricular Bluetooth PS3. Está siendo emparejado, pero no se conectará. Puedo conectar manualmente el auricular cuando entro en la configuración de bluetooth. –

Respuesta

1

pensé que no debe asignar un UUID específico como parámetro de conexión, excepto que usted sabe que esto es el GUID exacta proporcionada por el auricular. No estoy seguro. Pero espero que pueda ayudarte.

¡Buena suerte!

Fantasía

2

@CHRIS Hey i en realidad sólo descubrió el problema. Golpea el clavo en la cabeza con el connectThread, sin embargo, necesita usar el UUID ("00001108-0000-1000-8000-00805F9B34FB") para el perfil del auricular. Estoy usando un auricular Jabra y funciona para mí. ¡Déjeme saber si usted tiene preguntas! Gracias!

+0

Algunos auriculares bluetooth pueden no proporcionar este UUID de perfil, aunque es el perfil básico para este propósito. Pero como el perfil de nivel "superior" para el uso del kit para automóvil agrega algunas características interesantes (número de rellamada, etc.), primero debe probar HandsFreeProfile (HFP) con el UUID "0000111E-0000-1000-8000-00805F9B34FB". – Schlangi

1

Estoy estudiando un problema similar también ... - Cómo conectar el perfil de auriculares con la APLICACIÓN. y entonces vi esta respuesta aquí: https://stackoverflow.com/a/5711736/769556

Básicamente esta conexión perfil de nivel de auriculares se hace internamente por Android (y no hay acceso a nivel de aplicación para establecer conexiones)

Así. .. @ Chris Mattmiller ¿has encontrado una respuesta diferente?

Cuestiones relacionadas