Android: cambiar entre dispositivos Bluetooth SPP
Tengo dos impresoras Bluetooth diferentes. Bixolon SPP-R200 y Fujitsu FTP-628WSL110. Puedo conectarme a cada uno de ellos por separado (utilizando un Samsung Galaxy SII), imprimir, desconectar y volver a conectar muy bien. Sin embargo, si apago el Bixolon y trato de emparejarme con el Fujitsu (anteriormente no emparejado, Bixolon aún está emparejado), entonces falla cuando se intenta conectar al socket creado. Lo mismo al revés.
Aquí está el mensaje de error:
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): Failed to connect to rfcomm socket.
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): java.io.IOException: Service discovery failed
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:406)
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:217)
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at MyApp.BluetoothConnection.connect(BluetoothConnection.java:171)
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at MyApp.AbstractBluetoothPrinter.connect(AbstractBluetoothPrinter.java:34)
Aquí está el código, que hace el intento de conexión, la línea que falla en las circunstancias explicadas es btSocket.connect (); - excepción ver más arriba:
/** Is set in connect() */
private BluetoothSocket btSocket = null;
/** Is set prior to connect() */
private BluetoothSocket btDevice;
public boolean connect(){
try {
btSocket = btDevice.createRfcommSocketToServiceRecord("00001101-0000-1000-8000-00805F9B34FB");
if (btDevice.getName().startsWith("FTP")) {
//Special treatment for the fujitsu printer
SystemClock.sleep(1000);
}
} catch (Throwable e) {
LogCat.e(TAG, "Failed to create rfcomm socket.", e);
return false;
}
try {
// Stop Bluetooth discovery if it's going on
BluetoothHandler.cancelDiscovery();
// This fails under the described circumstances
btSocket.connect();
} catch (Throwable e) {
LogCat.e(TAG, "Failed to connect to rfcomm socket.", e);
return false;
}
// Obtain streams etc...
}
Estoy usando elmismo UUID para conectarse aambos dispositivos (pero solo se enciende un dispositivo a la vez, nunca se encienden al mismo tiempo), el conocido UUID de SPP de la API del SDK:
00001101-0000-1000-8000-00805F9B34FB
Lo que me hace preguntarme: ¿Podría ser que necesito un UUID diferente para cada dispositivo? Si es así, ¿alguna idea de cuál?