java.io.IOException异常:服务发现失败 [英] java.io.IOException: Service discovery failed

查看:820
本文介绍了java.io.IOException异常:服务发现失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用程序中使用两对智能手机之间的蓝牙连接工作。蓝牙逻辑是基于著名的BluetoothChat SDK例如:服务类管理服务器接受()线程,客户端线程连接()和读取/插座上写一个主题。

一切工作正常,但如果我关闭活动连接(无论是从客户端或服务器端),那么所有连续尝试启动一个新的连接将会失败,此错误:

  java.io.IOException异常:服务发现失败

经过一番研究,我来想,这是UUID的问题。我使用的BTChat例子的UUID( fa87c0d0-AFAC-11de-8a39-0800200c9a66 ),但问题仍然存在与另一个随机UUID(这是 31ef5990-dc20-11e2-a28f-0800200c9a66 )。

下面是相关客户logcat的。 (客户端连接()是失败):

  E / BluetoothService.cpp:stopDiscoveryNative:在StopDiscovery的D-Bus错误:org.bluez.Error.Failed(无效的搜索会话)
D / BluetoothService:清理失败UUID渠道查找:30:17:8:A7:C6:C3 fa87c0d0-AFAC-11de-8a39-0800200c9a66
        java.io.IOException异常:服务发现失败

D型总线错误可能是由 cancelDiscovery()是Android的文档显示前来调用connect()。我认为,失败UUID渠道查找是真正的问题,但我不知道如何解决这一问题。我应该使用其他(著名?)UUID?

如果需要的话,我可以告诉code片段。然而,这个问题很逻辑上类似于BluetoothChat。


解决方案

 方法M = device.getClass()。实现getMethod(createRfcommSocket,新的Class [] {} int.class );
TMP =(的BluetoothSocket)m.invoke(设备,1);

&安培;

  M = mAdapter.getClass()实现getMethod(listenUsingRfcommOn,新的Class [] {} int.class)。
TMP =(BluetoothServerSocket)m.invoke(mAdapter,BLUETOOTH_CHANNEL);

嗯....我不是一个BT的专家,但我知道我的code。使用反射作品,未经UUID。我不认为这是一个很好的解决方案,如果你想要的东西干净,但我只知道,在我的情况,它的工作原理(在2.3.6):)

I'm working on an Android app using Bluetooth connectivity between two paired smartphones. The Bluetooth logic is based on the famous BluetoothChat SDK example: a "service" Class managing a thread for server accept(), a thread for client connect() and a thread for reading/writing on the socket.

Everything works fine, except if I close an active connection (both from client or server side), then all successive attempts to start a new connection will fail with this error:

java.io.IOException: Service discovery failed

After some research, I've come to think this is a problem with UUID. I'm using the UUID of the BTChat example (fa87c0d0-afac-11de-8a39-0800200c9a66), but the problem remains with another random UUID (it was 31ef5990-dc20-11e2-a28f-0800200c9a66).

Here is the relevant client logcat. (The client connect() is what fails):

E/BluetoothService.cpp: stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
D/BluetoothService: Cleaning up failed UUID channel lookup: 30:17:C8:A7:C6:C3 fa87c0d0-afac-11de-8a39-0800200c9a66
        java.io.IOException: Service discovery failed

The D-Bus error probably is caused by the cancelDiscovery() that Android docs suggests to call before connect(). I think that failed UUID channel lookup is the real problem, but I have no idea how to fix this. Should I use another (well-known?) UUID?

If needed, I can show code snippets. Yet this problem is very logically similar to BluetoothChat.

解决方案

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

&

m = mAdapter.getClass().getMethod("listenUsingRfcommOn", new Class[] { int.class });
tmp = (BluetoothServerSocket) m.invoke(mAdapter, BLUETOOTH_CHANNEL);

Well .... I'm not a BT specialist, but I know that my code works without UUID using reflection. I don't think it's a good solution if you want something clean, but I just know that, in my case, it works (On 2.3.6) :)

这篇关于java.io.IOException异常:服务发现失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆