我能夠首次連接到外部成對的藍牙硬件。之後,如果我重複連接/ disconect程序有時會得到例外。Post ICS版本中的藍牙連接問題
Exception = read failed, socket might closed or timeout, read ret: -1
,並能夠連接again.Sometimes第二審判本身多次試驗後成功
問題與設備觀察:Nexux7(版本4.3)和MotoG(奇巧)
代碼連接:
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(devAddress);
socket = device.createRfcommSocketToServiceRecord(MY_UUID);
和呼叫從的AsyncTask socket.connect()
代碼關閉插座:主題
if (in != null) {
Logger.loge(CLASS_NAME + "." + "resetConnection", "in != null");
try {
in.close();
} catch (Exception e) {
// Log.d(TAG,"exception in closing inputstream - " + e.getMessage());
}
in = null;
}
if (out != null) {
Logger.loge(CLASS_NAME + "." + "resetConnection", "out != null");
try {
out.close();
} catch (Exception e) {
// Log.d(TAG,"exception in closing outputstream - " + e.getMessage());
}
out = null;
}
if (socket != null) {
Logger.loge(CLASS_NAME + "." + "resetConnection", "socket != null");
try {
socket.close();
} catch (Exception e) {
//Log.d(TAG,"exception in closing socket - " + e.getMessage());
}
socket = null;
}
我也跟着鏈接
https://groups.google.com/forum/#!topic/android-developers/UxY5xME6V5s
Android Bluetooth: java.io.IOException: Service discovery failed
Disconnect a bluetooth socket in Android
android bluetooth can't connect
所提供的解決方案都不能幫助我解決問題。
任何幫助將不勝感激...
感謝
我們無法重新初始化連接,兩端編程方式,作爲其中之一是外部硬件,而不是手機。 – heyjii