我正在开发一个简单的蓝牙应用程序,我想发送短信。在尝试配对设备时遇到问题,它会抛出异常“java.io.IOException:Service discovery failed”。有关详细信息,我将在此处发布代码。 在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();
}
}
感谢任何形式的帮助,
答案 0 :(得分:0)
尝试使用此UUID:
fa87c0d0-afac-11de-8a39-0800200c9a66
出于某种原因,这是我唯一可以上班的UUID ......我不知道为什么。