The*_*sey 20 android bluetooth rfcomm
我正在尝试使用谷歌提供的蓝牙聊天示例API应用程序连接到连接到另一台设备的蓝牙RS232适配器.这是应用程序供参考:
http://developer.android.com/resources/samples/BluetoothChat/index.html
以下是RS232连接器的规格表,仅供参考:
http://serialio.com/download/Docs/BlueSnap-guide-4.77_Commands.pdf
那么问题是,当我连接到设备时:
mmSocket.connect(); (BluetoothSocket::connect())
Run Code Online (Sandbox Code Playgroud)
我总是得到IOException该connect()方法抛出的错误.当我toString对异常进行处理时,我得到"服务发现失败".我的问题主要是什么导致IOException在连接方法中被抛出的情况?我知道那些是在某个地方的源代码,但我不确切知道你编写应用程序的java层和包含实际堆栈接口的C/C++层.我知道它使用的是用C/C++编写的bluez蓝牙堆栈,但不确定它是如何与java层绑定的,这就是我认为抛出异常的东西.指点我可以尝试解剖这个问题的任何帮助都是不可思议的.
还要注意我能够与RS232适配器配对,但我永远无法实际连接.以下是logcat输出以获取更多参考:
I/ActivityManager( 1018): Displayed activity com.example.android.BluetoothChat/.DeviceListActivity: 326 ms (total 326 ms) E/BluetoothService.cpp( 1018): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) D/BluetoothChat( 1729): onActivityResult -1 D/BluetoothChatService( 1729): connect to: 00:06:66:03:0C:51 D/BluetoothChatService( 1729): setState() STATE_LISTEN -> STATE_CONNECTING E/BluetoothChat( 1729): + ON RESUME + I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_CONNECTING I/BluetoothChatService( 1729): BEGIN mConnectThread E/BluetoothService.cpp( 1018): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) E/BluetoothEventLoop.cpp( 1018): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1498/hci0/dev_00_06_66_03_0C_51 I/BluetoothChatService( 1729): CONNECTION FAIL TOSTRING: java.io.IOException: Service discovery failed D/BluetoothChatService( 1729): setState() STATE_CONNECTING -> STATE_LISTEN D/BluetoothChatService( 1729): start D/BluetoothChatService( 1729): setState() STATE_LISTEN -> STATE_LISTEN I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_LISTEN V/BluetoothEventRedirector( 1080): Received android.bleutooth.device.action.UUID I/NotificationService( 1018): enqueueToast pkg=com.example.android.BluetoothChat callback=android.app.ITransientNotification$Stub$Proxy@446327c8 duration=0 I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_LISTEN E/BluetoothEventLoop.cpp( 1018): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1498/hci0/dev_00_06_66_03_0C_51 V/BluetoothEventRedirector( 1080): Received android.bleutooth.device.action.UUID
我正在尝试连接的设备是00:06:66:03:0C:51我可以扫描的设备,显然配对就好了.
以下是与类似问题的合并,该问题已在此处通过所选答案成功解决:
Android API提供了使用listenUsingRfcommWithServiceRecord()来设置套接字和createRfcommSocketToServiceRecord()来连接到该套接字的示例.
我正在尝试使用BlueSMiRF Gold芯片连接到嵌入式设备.我工作的Python代码(使用PyBluez库),我想移植到Android,如下所示:
sock = bluetooth.BluetoothSocket(proto=bluetooth.RFCOMM)
sock.connect((device_addr, 1))
return sock.makefile()
Run Code Online (Sandbox Code Playgroud)
...所以连接的服务只是定义为通道1,没有任何SDP查找.
作为我在Android API中看到的唯一记录的机制是对UUID进行SDP查找,我有点不知所措.使用我的Linux主机上的"sdptool browse"是空的,所以我猜测有问题的芯片缺乏SDP支持.
The*_*sey 34
好的简短回答是我必须使用此UUID才能连接到我的SPP设备:
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
Run Code Online (Sandbox Code Playgroud)
我试图改变它,因为我认为只有"1101"部分是重要的,因为我看到提到SPP的东西遍布在intertubes的地方,但这使它不再连接.显然,特定的UUID应该用于连接到通用SPP设备.无论如何只是觉得我会把它发布在这里,所以任何这类问题的人都有答案.花了我3天左右找到它大声笑!
| 归档时间: |
|
| 查看次数: |
53709 次 |
| 最近记录: |