简体   繁体   中英

Dual SPP bluetooth connexion on android

I have been asked to connect 2 concurrent bluetooth SPP devices (Serial port over bluetooth) on an Android tablet.

I used the bluetooth chat as a base to connect one, but I'm lost when it comes to connecting to 2 devices at the same time.

The goal is to collect data from two remote devices and compare the data.

The tablet can not act as a server, it must be client to those devices.

I looked around but did not found any source examples.

If someone could help...

Thanks Cedric

Finally I cloned the class containing the connection threads and doubled the handler in the main activity. I also doubled the menu in order to connect to the 2 devices and after a few tweakings, works like a charm !

it really is simple. just do everything 2 times.

    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.");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM