Android Bluetooth: java.io.IOException: Service discovery failed

两盒软妹~` 提交于 2019-12-03 16:49:48

Maybe you can try adding thread.sleep for a second? See this discussion:

"The only way I've been able to fix the problem is by adding a thread.sleep for a second before closing the connection."

also see dan's two consecutive comments on this thread:

"I was able to get this to run only after separating the calls to findBT(); openBT();

Otherwise, mmSocket.connect(); throws an exception, “Service discovery failed”

but if I put findBT() in onCreate() and just use the button for openBT(); it works fine.

Or, if I make a second button, one for each, it works fine.

Suggestions?"

the excerpts from the second comment:

Set pairedDevices = mBluetoothAdapter.getBondedDevices();
mmDevice = mBluetoothAdapter.getRemoteDevice(“00:06:66:46:5A:91″);
if (pairedDevices.contains(mmDevice))
{
statusText.setText(“Bluetooth Device Found, address: ” + mmDevice.getAddress() );
Log.d(“ArduinoBT”, “BT is paired”);
}

where I entered the address of my Bluetooth device. The original code finds the device and returns the correct address, but mmSocket.connect(); generates an exception “java.io.IOException: Service discovery failed”

Suggestions?

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