我被要求在Android平板电脑上同时连接两个蓝牙SPP设备(蓝牙串口)。
我使用蓝牙聊天作为基础来连接一台设备,但当我同时连接两台设备时,我就迷路了。
目标是从两个远程设备收集数据并比较数据。
平板电脑不能充当服务器,它必须是这些设备的客户端。
我看了看周围,但没有找到任何源码示例。
如果有人能帮上忙。
谢谢塞德里克
发布于 2011-09-02 10:12:28
最后,我克隆了包含连接线程的类,并在主活动中加倍了处理程序。我还加倍了菜单,以便连接到两个设备,并在几个调整后,工作起来像一个护身符!
发布于 2016-04-13 04:41:00
这真的很简单。每件事都要做两次。
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.");https://stackoverflow.com/questions/7053804
复制相似问题