我正在开发一个简单的蓝牙应用程序,我想在其中发送短信。尝试配对设备时遇到问题,它会抛出异常“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();
}
}
任何形式的帮助表示赞赏,