我引用了这个链接: Disconnect a bluetooth socket in Android
但它仍然不适合我。始终通过BluetoothSocket :: connect()
的异常我的情况是,如果用户通过手机配对并连接了远程的bt设备,我该如何以编程方式断开它?
我有一种预感,如果我想要断开连接,我应该关闭输入,输出流然后执行BluetoothSocket关闭。我无法在任何地方找到连接设备上的套接字。 API createRfcommSocketToServiceRecord是创建套接字。谢谢!
PS,远程bt设备是耳机
答案 0 :(得分: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; }