我正在尝试通过蓝牙将字符串从我的 Nexus S 发送到另一台 android 设备。代码如下:
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)
item.getMenuInfo();
if(item.getItemId() == 0)
{
BluetoothDevice selDev = pairedDevices.get(info.position);
TelephonyManager tman = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
byte[] toSend = "a text".getBytes();
try
{
BluetoothSocket socket = selDev.createInsecureRfcommSocketToServiceRecord(
UUID.fromString("00001105-0000-1000-8000-00805F9B34FB"));
OutputStream out = socket.getOutputStream();
out.write(toSend);
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
return true;
}
但我总是得到这个 IO 异常:java.io.IOException: Transport endpoint is not connected
怎么了?