通过蓝牙将 Android 设备传输至诺基亚

发布于 2024-12-17 09:17:32 字数 1297 浏览 0 评论 0原文

我正在尝试将我的 Android 手机连接到我的诺基亚手机。我可以通过我的 Andorid 应用程序发现诺基亚手机。我可以成功创建套接字:

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 和互联网上寻求帮助,但没有找到任何帮助。

I am trying to connect my Android phone to my Nokia phone. I can discover the Nokia phone through my Andorid application. I can create the socket successfully:

btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);

But when I try to connect to the nokia phone there is an error in connection.
I am trying to run this sample provided in the link below:

http://www.anddev.org/code-snippets-for-android-f33/serial-over-bluetooth-simple-test-client-t11106.html

And an error is occured when the code btSocket.connect() which is present in the onResume() method is executed:

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)

And this is the UUID I am using:

private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");`

Kindly let me know where I am going wrong. I tried to look for help in Stackoverflow and on the internet in general, but no help was found.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦 2024-12-24 09:17:32

我使用了这里找到的解决方案:在Android上使用蓝牙服务发现失败异常< /a>

由于某种我不清楚的原因,反射在某些普通方法不起作用的设备上起作用。试试这个:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class} );
btSocket = (BluetoothSocket) m.invoke(device, 1);      

I used the solution found here: Service discovery failed exception using Bluetooth on Android

For some reason unclear to me, reflection works on some devices where the ordinary method doesn't work. Try this:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class} );
btSocket = (BluetoothSocket) m.invoke(device, 1);      
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文