我正在开发一个简单的蓝牙应用程序,我想发送文本消息。在尝试配对设备时遇到问题,它会抛出异常“java.io.IOException:服务发现失败”。欲了解更多详情,我在此发布代码。在LG的手机Android版本 移植的应用程序2.3.3问题与蓝牙设备配对
private static final UUID MY_UUID = UUID.fromString("00000003-0000-1000-8000-00805F9B34FB");
BluetoothDevice btDevice = BluetoothActivity.btDevices.get(position).getBtDevice();
clientSocket = btDevice.createRfcommSocketToServiceRecord(MY_UUID);
//Method m = btDevice.getClass().getMethod("createRfcommSocketToServiceRecord", new Class[] { UUID.class });
//clientSocket =(BluetoothSocket) m.invoke(btDevice, MY_UUID);
//Method m = btDevice.getClass().getMethod("createRfcommSocket",new Class[] { int.class });
//clientSocket =(BluetoothSocket) m.invoke(btDevice, 1);
if(clientSocket!=null)
{
if(BluetoothActivity.btAdapter.isDiscovering()){
BluetoothActivity.btAdapter.cancelDiscovery();
}
//facing issue during paring
clientSocket.connect();
tmpOut = clientSocket.getOutputStream();
tmpOut.write("HelloWorld.txt".getBytes());
if(tmpOut!=null){
tmpOut.close();
}
}
任何形式的帮助表示赞赏,
因此'clientSocket.connect()'引起异常的线? btDevice是否被正确设置为您想要的设备?我发现我需要在设置套接字之前通过手机设置手动连接到其他BT设备。 –
@ Pravin008您只能连接Android设备或PC与其他设备? – Venky