开发者

Android 2.1 How to disconnect a connected bt device

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; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜