Frequent random failures (Service discovery failed) in createInsecureRfcommSocketToServiceRecord

穿精又带淫゛_ 提交于 2019-12-11 00:57:15

问题


I am attempting to establish an insecure Bluetooth socket connection between two Android devices. I control the software on both ends. One end uses listenUsingInsecureRfcommWithServiceRecord to listen for a connection, the other end uses createInsecureRfcommSocketToServiceRecord to connect. This works. Sometimes.

The "sometimes" is my problem. In about 20% of the attempts, it fails and throws the following exception:

java.io.IOException: Service discovery failed
    at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:403)
    at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:213)
    at com.example.bluetoothpoke.MainActivity$1.onClick(MainActivity.java:34)

Both devices are awake with screen on. The distance between the devices is around 1m (10 cm and 3m don't make a difference). Neither device is performing discovery. Both devices are discoverable (making both non-discoverable doesn't change anything, either).

Do I have to assume it is normal because of the wireless interface and just try again on failure, or is there something I can do? Shouldn't it work more reliably given that I am at a very comfortable distance?

Note: I found lots of similar questions, but the ones I found are either about "doesn't work at all", connecting to a non-Android device, or both.

来源:https://stackoverflow.com/questions/14642014/frequent-random-failures-service-discovery-failed-in-createinsecurerfcommsocke

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!