问题描述
我试图创建一个基本的蓝牙应用程序,用于测试设备。
I'm trying to create a basic bluetooth application, for testing the device.
我从developer.android得到了code。这里是链接:http://developer.android.com/guide/topics/connectivity/bluetooth.html#ConnectingDevices
I got the code from developer.android. Here is the link : http://developer.android.com/guide/topics/connectivity/bluetooth.html#ConnectingDevices
下面是运行我的线程code部分:
Here is run part of my thread code:
public void run() {
mBluetoothAdapter.cancelDiscovery();
Log.i(TAG, "Discovery Cancel!");
try {
Log.i(TAG, "Connection Started");
mmSocket.connect();
Log.i(TAG, "Connection Ended");
} catch (IOException e) {
try {
Log.e(TAG, "Connection Failed", e);
mmSocket.close();
} catch (IOException e2) {
Log.e(TAG, "Connection Close Failed", e2);
}
return;
}
无论我都试过 mmSocket.connect();
永远不会奏效。总是抛出IOException,我得到的日志从我的logcat:
Whatever I have tried mmSocket.connect();
never works. Always throws an IOException and I get that log from my logcat:
java.io.IOException异常:服务发现失败
在android.bluetooth.BluetoothSocket $ SdpHelper.doSdp(BluetoothSocket.java:403)
在android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:213)
java.io.IOException: Service discovery failed
at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:403)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:213)
我已经看了这些文章,并尝试了书面的东西,没有人已经解决了我的问题。
I've looked at these articles, and tried the written things, none of them has solved my problem.
Android蓝牙:服务发现失败,连接到台式机/笔记本电脑
Service发现在Android
Bluetooth在Android ICS不可能连接
Android蓝牙java.io.IOException异常:连接被拒绝
顺便说一下我的工作在Android上的IC 4.0.4。
Btw I'm working on android ics 4.0.4.
我知道这不是设备的问题,因为我已经尝试了不同设备上的这个程序。
I know that is not device problem, cause I've tried this app on different devices.
推荐答案
我不知道,我还是不明白的UUID的东西,但问题是UUID。我用这是我从内核日志中得到了UUID,它是 00001105-0000-1000-8000-00805F9B34FB
。
I don't know and I still don't understand the UUID stuff but the problem was the UUID. I'm using the UUID which I got from the kernel logs and it is 00001105-0000-1000-8000-00805F9B34FB
.
这篇关于Android的蓝牙连接 - 服务发现失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!