I have referenced the link: Disconnect a bluetooth socket in Android
but still it doesn't work for me. always through an exception at BluetoothSocket::connect()
My case is that if User has paired and connected a remote bt device via the phone, how can I programmatically disconnect it??
I got a hunch that if I want the connection to be disconnected I should close the input, output stream then perform BluetoothSocket close. And I can't 开发者_Python百科find anywhere to get the socket on the connected device. the API createRfcommSocketToServiceRecord is to create a socket. Thank you!
PS, the remote bt device is headset
follow the below procedure
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; }
精彩评论