Android蓝牙聊天示例无效,无法连接设备
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android蓝牙聊天示例无效,无法连接设备相关的知识,希望对你有一定的参考价值。
我在https://developer.android.com/samples/BluetoothChat/index.html中一直在尝试蓝牙聊天,但我的设备(Nexus 7)无法使用该示例配对/连接到我的笔记本电脑(华硕)。
我正在使用示例中的默认UUID。我还需要在代码中修改其他任何内容才能使其正常工作吗?以下是我尝试连接时logcat的结果。
08-26 17:33:16.259 3834-3834/? I/art: Late-enabling -Xcheck:jni
08-26 17:33:16.510 3834-3834/com.example.android.bluetoothchat
I/MainActivity: Ready
08-26 17:33:16.513 3834-3834/com.example.android.bluetoothchat
D/BluetoothChatService: start
08-26 17:33:16.521 3834-3834/com.example.android.bluetoothchat
W/BluetoothAdapter: getBluetoothService() called with no
BluetoothManagerCallback
08-26 17:33:16.526 3834-3864/com.example.android.bluetoothchat
D/BluetoothChatService: Socket Type: SecureBEGIN mAcceptThreadThread[Thread-
479,5,main]
08-26 17:33:16.526 3834-3834/com.example.android.bluetoothchat
W/BluetoothAdapter: getBluetoothService() called with no
BluetoothManagerCallback
08-26 17:33:16.529 3834-3834/com.example.android.bluetoothchat
D/BluetoothChatService: updateUserInterfaceTitle() 0 -> 1
08-26 17:33:16.529 3834-3865/com.example.android.bluetoothchat
D/BluetoothChatService: Socket Type: InsecureBEGIN
mAcceptThreadThread[Thread-480,5,main]
08-26 17:33:16.543 3834-3866/com.example.android.bluetoothchat
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: false
08-26 17:33:16.554 3834-3834/com.example.android.bluetoothchat D/Atlas:
Validating map...
08-26 17:33:16.640 3834-3866/com.example.android.bluetoothchat D/libEGL:
loaded /system/lib/egl/libEGL_tegra.so
08-26 17:33:16.657 3834-3866/com.example.android.bluetoothchat D/libEGL:
loaded /system/lib/egl/libGLESv1_CM_tegra.so
08-26 17:33:16.691 3834-3866/com.example.android.bluetoothchat D/libEGL:
loaded /system/lib/egl/libGLESv2_tegra.so
08-26 17:33:16.738 3834-3866/com.example.android.bluetoothchat
I/OpenGLRenderer: Initialized EGL, version 1.4
08-26 17:33:16.748 3834-3866/com.example.android.bluetoothchat
D/OpenGLRenderer: Enabling debug mode 0
08-26 17:33:20.384 3834-3834/com.example.android.bluetoothchat
D/DeviceListActivity: doDiscovery()
08-26 17:33:25.394 3834-3834/com.example.android.bluetoothchat
D/BluetoothChatService: connect to: 28:C2:DD:8C:30:BC
08-26 17:33:25.401 3834-3834/com.example.android.bluetoothchat
D/BluetoothChatService: updateUserInterfaceTitle() 1 -> 2
08-26 17:33:25.402 3834-4016/com.example.android.bluetoothchat
I/BluetoothChatService: BEGIN mConnectThread SocketType:Secure
08-26 17:33:25.423 3834-4016/com.example.android.bluetoothchat
W/BluetoothAdapter: getBluetoothService() called with no
BluetoothManagerCallback
08-26 17:33:27.479 3834-4016/com.example.android.bluetoothchat
D/BluetoothChatService: updateUserInterfaceTitle() 2 -> 0
08-26 17:33:27.479 3834-4016/com.example.android.bluetoothchat
D/BluetoothChatService: start
08-26 17:33:27.479 3834-4016/com.example.android.bluetoothchat
D/BluetoothChatService: updateUserInterfaceTitle() 0 -> 0
我也尝试了各种其他蓝牙聊天示例,但每次都面临“无法连接设备”。
I/BluetoothChatService: BEGIN mConnectThread SocketType:Secure
08-26 17:33:25.423 3834-4016/com.example.android.bluetoothchat
W/BluetoothAdapter: getBluetoothService() called with no
BluetoothManagerCallback
可能是这个问题阻止设备成功削减吗?任何使这项工作的建议都会很棒!
答案
这可能是UUID的问题。
尝试使用UUID.fromString("00001101-0000-1000-8000-00805f9b34fb")
查看详细信息https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
以上是关于Android蓝牙聊天示例无效,无法连接设备的主要内容,如果未能解决你的问题,请参考以下文章