我正在尝试连接我的Android手机和我的诺基亚手机。我可以通过我的安卓应用程序找到诺基亚手机。我可以成功创建套接字:
btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
但是当我尝试连接到诺基亚手机有一个错误的连接。我正试图运行下面链接中提供的这个示例:
http://www.anddev.org/code-snippets-for-android-f33/serial-over-bluetooth-simple-test-client-t11106.html并且当onResume()
方法中的代码btSocket.connect()
执行时发生错误:
Logcat:
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和互联网上寻找帮助,但没有找到帮助。
我使用了这里找到的解决方案:在Android上使用蓝牙服务发现失败异常
由于我不清楚的原因,反射在一些普通方法不起作用的设备上起作用。试试这个:
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class} );
btSocket = (BluetoothSocket) m.invoke(device, 1);