Android蓝牙UUID串口导致异常
我正在使用 Android 开发示例项目 BluetoothChat。
http://developer.android.com/resources/samples/BluetoothChat/index.html 我在 Archos 43 上运行它并尝试与串行蓝牙适配器进行通信。 要与适配器通信,我需要使用 UUID 00001101-0000-1000-8000-00805F9B34FB。 但是,当我这样做时,我在这一行收到空指针异常: 套接字 = mmServerSocket.accept();
如果我使用不同的 UUID,则不会出现此问题,但无法连接到串行适配器。 如果我使用 Motorola Droid 而不是 Archos 43,则不会出现此问题。
从一些错误消息来看,我认为 Archos 使用的是 bluez 堆栈。
任何想法为什么这个 UUID 和堆栈的组合在调用accept()函数时会导致异常?
这是周围的代码(您可以从上面的链接获取整个源代码)
public void run() {
if (D) Log.d(TAG, "BEGIN mAcceptThread" + this);
setName("AcceptThread");
BluetoothSocket socket = null;
// Listen to the server socket if we're not connected
while (mState != STATE_CONNECTED) {
try {
// This is a blocking call and will only return on a
// successful connection or an exception
socket = mmServerSocket.accept();
} catch (IOException e) {
Log.e(TAG, "accept() failed", e);
break;
}
日志中的一些错误消息:
04-25 21:05:33.278: ERROR/BluetoothChatService(3321):listen() failed
04-25 21:05: 33.278:错误/BluetoothChatService(3321):java.io.IOException:无法注册BluetoothChat
04-25 21:05:33.278的SDP记录:错误/BluetoothChatService(3321):在android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter。爪哇:778)
I'm using the Android development sample project BluetoothChat.
http://developer.android.com/resources/samples/BluetoothChat/index.html
I'm running it on an Archos 43 and trying to communicate with a serial to bluetooth adapter.
To communicate with the adapter I need to use UUID 00001101-0000-1000-8000-00805F9B34FB.
However, when I do that, I get a Null Pointer Exception at this line:
socket = mmServerSocket.accept();
If I use a different UUID I do not have this problem, however I cannot connect to the serial adapter.
If I use a Motorola Droid instead of the Archos 43, I do not have this problem.
From some error messages, I think the Archos is using the bluez stack.
Any ideas why the combination of this UUID and stack would cause an exception when calling the accept() function?
Here's the surrounding code (you can get the whole source from the link above)
public void run() {
if (D) Log.d(TAG, "BEGIN mAcceptThread" + this);
setName("AcceptThread");
BluetoothSocket socket = null;
// Listen to the server socket if we're not connected
while (mState != STATE_CONNECTED) {
try {
// This is a blocking call and will only return on a
// successful connection or an exception
socket = mmServerSocket.accept();
} catch (IOException e) {
Log.e(TAG, "accept() failed", e);
break;
}
Some error messsages from the log:
04-25 21:05:33.278: ERROR/BluetoothChatService(3321): listen() failed
04-25 21:05:33.278: ERROR/BluetoothChatService(3321): java.io.IOException: Not able to register SDP record for BluetoothChat
04-25 21:05:33.278: ERROR/BluetoothChatService(3321): at android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter.java:778)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否更改了“class AcceptThread”的构造函数,在其中使用了此函数“listenUsingRfcommWithServiceRecord()”?
我在 archos 70 上使用相同的 UUID,并且没有收到任何蓝牙连接错误。(如果是间歇性的,请尝试重新启动 archos。)由于某些原因,我想将其添加为评论,但我没有看到评论!
Did you change the constructor of "class AcceptThread" , where you use this function "listenUsingRfcommWithServiceRecord()" ?
I'm using the same UUID on archos 70 and i dont get any bluetooth connection errors.( Try restarting the archos if its intermittent.) I wanted to add this as comments for some reasons i dont see a comment !
最终问题通过爱可视的固件更新得到解决。
It ends up the problem was solved with a firmware update from Archos.