2011-04-12 59 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; }