【问题标题】:bluetoothsocket.connect() throws exception in the second runbluetoothsocket.connect() 在第二次运行时抛出异常
【发布时间】:2016-03-05 08:03:56
【问题描述】:

我创建了一个Android应用程序通过蓝牙串行适配器连接到Arduino,当我第一次运行该应用程序时它工作正常,之后bluetoothsocket.connect()抛出异常,代码如下:- 套接字连接:

mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mBluetoothAdapter.cancelDiscovery();
mmSocket.connect();
// send data
mmSocket.close();

不知道问题出在哪里

【问题讨论】:

  • android.bluetooth.BluetoothSocket.readAll android.bluetooth.BluetoothSocket.readInt android.bluetooth.BluetoothSocket.connect PhoneStateReceiver.openBT onCallStateChanged handleMessage dispatchMessage
  • 编辑您的答案并添加完整的堆栈跟踪。带格式
  • @Salman 我无法添加为评论,所以我添加为答案
  • 您可以随时edit您的问题。

标签: android bluetooth arduino


【解决方案1】:

问题解决了,问题是 bluetoothsocket.close(); 我不应该调用这个函数

【讨论】:

    【解决方案2】:

    只有在发送完所有数据且不再需要发送时才应关闭套接字,如果需要发送更多数据,请在重新连接之前重新配置套接字

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      相关资源
      最近更新 更多