【问题标题】:Android 2.1 How to disconnect a connected bt deviceAndroid 2.1 如何断开已连接的 bt 设备
【发布时间】:2011-04-12 02:51:02
【问题描述】:

我已经引用了链接: Disconnect a bluetooth socket in Android

但它仍然对我不起作用。总是通过 BluetoothSocket::connect() 的异常

我的情况是,如果用户通过手机配对并连接了远程 bt 设备,我该如何以编程方式断开它??

我有一种预感,如果我想断开连接,我应该关闭输入、输出流,然后执行 BluetoothSocket 关闭。而且我找不到任何地方可以连接设备上的插座。 API createRfcommSocketToServiceRecord 是创建一个套接字。谢谢!

PS,远程bt设备是耳机

【问题讨论】:

    标签: android


    【解决方案1】:

    按照以下步骤进行

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      相关资源
      最近更新 更多