首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android上的双SPP蓝牙连接

android上的双SPP蓝牙连接
EN

Stack Overflow用户
提问于 2011-08-14 06:50:48
回答 2查看 2.3K关注 0票数 3

我被要求在Android平板电脑上同时连接两个蓝牙SPP设备(蓝牙串口)。

我使用蓝牙聊天作为基础来连接一台设备,但当我同时连接两台设备时,我就迷路了。

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

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

我看了看周围,但没有找到任何源码示例。

如果有人能帮上忙。

谢谢塞德里克

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-02 10:12:28

最后,我克隆了包含连接线程的类,并在主活动中加倍了处理程序。我还加倍了菜单,以便连接到两个设备,并在几个调整后,工作起来像一个护身符!

票数 2
EN

Stack Overflow用户

发布于 2016-04-13 04:41:00

这真的很简单。每件事都要做两次。

代码语言:javascript
复制
    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.");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7053804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档