2011-08-13 111 views
3

我被要求在Android平板电脑上连接2个并发的蓝牙SPP设备(蓝牙串口)。Android上的双SPP蓝牙连接

我使用蓝牙聊天作为基础来连接一个,但我在同时连接到两个设备时丢失了。

目标是从两个远程设备收集数据并比较数据。

平板电脑不能充当服务器,它必须是这些设备的客户端。

我环顾四周,但没有找到任何源代码示例。

如果有人可以帮助...

感谢 塞德里克

+0

我发现[链接] http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete [/链接] 但这只是服务器部分允许多个客户。 我需要客户端连接到多个服务器的部分。 – Cedric

回答

2

最后我克隆包含连接线程类和一倍的主要活动的处理程序。 我还将菜单加倍,以连接到2个设备,经过一些调整,就像一个魅力!

+0

不错的工作,现在只有当你可以在GitHub中开源代码时,它才会非常棒:) –

0

它确实很简单。只做2次。

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 

    bluetoothDevice = bluetoothAdapter.getRemoteDevice(btAddress1); 
    UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); 
    bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid); 

    Log.d(TAG, "start connect."); 
    bluetoothSocket.connect(); 
    Log.d(TAG, "finished connect."); 

    Log.d(TAG, "getting second adapter"); 
    bluetoothAdapter2 = BluetoothAdapter.getDefaultAdapter(); 
    Log.d(TAG, "getting second adapter success, getting device 2"); 
    bluetoothDevice2 = bluetoothAdapter2.getRemoteDevice(btAddress2); 
    Log.d(TAG, "getting second device success"); 
    UUID uuid2 = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); 
    bluetoothSocket2 = bluetoothDevice2.createInsecureRfcommSocketToServiceRecord(uuid2); 

    Log.d(TAG, "start connect 2."); 
    bluetoothSocket2.connect(); 
    Log.d(TAG, "finished connect 2.");