[英]Dual SPP bluetooth connexion on android
我被要求在 Android 平板电脑上连接 2 个并发蓝牙 SPP 设备(蓝牙上的串行端口)。
我使用蓝牙聊天作为基础来连接一个,但是在同时连接到 2 个设备时我迷路了。
目标是从两个远程设备收集数据并比较数据。
平板电脑不能充当服务器,它必须是这些设备的客户端。
我环顾四周,但没有找到任何源示例。
如果有人可以帮助...
谢谢塞德里克
最后,我克隆了包含连接线程的 class 并将主活动中的处理程序加倍。 我还将菜单翻了一番,以便连接到 2 台设备,经过一些调整,就像一个魅力!
这真的很简单。 只做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.");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.