[英]Issue with Bluetooth Device pairing
I am developing one simple Bluetooth application where I want to send a text message. 我正在开发一个简单的蓝牙应用程序,我想在其中发送文本消息。 Facing issues when trying to pair the devices, it throws exception “java.io.IOException: Service discovery failed”.
尝试配对设备时遇到问题,它引发异常“ java.io.IOException:服务发现失败”。 For more details I am posting code herewith.
有关更多详细信息,我将在此发布代码。 Ported application on LG phone Android version 2.3.3
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();
}
}
Any kind of help is appreciated, 任何帮助,我们都感激不尽,
Try using this UUID: 尝试使用此UUID:
fa87c0d0-afac-11de-8a39-0800200c9a66
for some reason, this was the only UUID I could ever get to work... I have no idea why. 由于某种原因,这是我唯一可以工作的UUID ...我不知道为什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.