我正在尝试将我的 Android 手机连接到我的诺基亚手机。我可以通过我的 Andorid 应用程序发现诺基亚手机。我可以成功创建套接字:
btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
但是当我尝试连接到诺基亚手机时出现连接错误。 我正在尝试运行以下链接中提供的示例:
当 onResume()
方法中的代码 btSocket.connect()
被执行时发生错误:
日志:
D/BluetoothAdapter( 176): checkBluetoothAddress
E/THINBTCLIENT( 4738): ON RESUME: Exception during connect.
E/THINBTCLIENT( 4738): java.io.IOException: Service discovery failed
E/THINBTCLIENT( 4738): at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377)
E/THINBTCLIENT( 4738): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201)<br>
E/THINBTCLIENT( 4738): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
这是我正在使用的 UUID
:
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");`
请让我知道我要去哪里错了。我尝试在 Stackoverflow 和互联网上寻求帮助,但没有找到任何帮助。
最佳答案
我使用了在这里找到的解决方案:Service discovery failed exception using Bluetooth on Android
出于某种我不清楚的原因,反射在某些普通方法不起作用的设备上有效。试试这个:
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class} );
btSocket = (BluetoothSocket) m.invoke(device, 1);
关于Android 到诺基亚数据传输通过蓝牙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8239997/