【问题标题】:Dual SPP bluetooth connexion on android安卓上的双 SPP 蓝牙连接
【发布时间】:2011-10-26 14:20:08
【问题描述】:

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

我以蓝牙聊天为基础连接了一个,但同时连接到两个设备时我迷失了。

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

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

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

如果有人可以帮忙...

谢谢 塞德里克

【问题讨论】:

标签: android sockets bluetooth


【解决方案1】:

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

【讨论】:

  • 干得好,现在只要你能在 GitHub 上开源你的代码,那就太棒了:)
【解决方案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.");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-19
    • 2014-08-31
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多