我有两个不同的蓝牙打印机。 BIXOLON SPP-R200和富士通FTP-628WSL110。 我可以连接到单独的每个人(使用三星Galaxy SII)打印,断开并重新连接就好了。 但是,如果我关掉BIXOLON并尝试配对的富士通(以前未成,BIXOLON仍配对),然后尝试连接到创建的套接字时失败。 同周围的其他方法。
以下是错误信息:
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)
下面是代码,这使得连接尝试,即下解释的情况下失败的线是btSocket.connect(); - 例外见上面:
/** 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...
}
我使用的是相同的 UUID连接到两个设备从SDK API(但在同一时间只有一台设备处于开机状态,他们从来没有在同一时间开启),著名的SPP UUID:
00001101-0000-1000-8000-00805F9B34FB
这让我怀疑:莫非,我需要对每个设备进行不同的UUID? 如果有任何想法有哪些?