2011-04-12 100 views
2

我有參考鏈接: Disconnect a bluetooth socket in Android的Android 2.1如何斷開連接的藍牙裝置

但仍沒有爲我工作。總是通過在的BluetoothSocket異常::連接()

我的情況是,如果用戶已經配對,並且通過電話連接的遠程BT設備,如何以編程斷開??

我有一種預感,如果我想的連接中斷,我應該關閉輸入,輸出流然後執行的BluetoothSocket接近。我找不到任何地方獲取所連接設備的插座中。該API createRfcommSocketToServiceRecord是創建一個插座。謝謝!

PS,所述遠程BT設備是耳機

回答

0

按照以下程序

if (mmSocket != null) { try { mmSocket.close(); } catch (Exception e) { Log.e("Exception", "while closing socket"+e.toString());  } mmSocket = null; } 
    if (mmOutStream != null) { try { mmOutStream.close(); } catch (Exception e) { Log.e("Exception", "while closing outstream"+e.toString()); } mmOutStream = null; } 
    if (mmInStream != null) { try { mmInStream.close(); } catch (Exception e) { Log.e("Exception", "while closing inputstream"+e.toString());} mmInStream = null; }