开发者

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 devi开发者_JS百科ces 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.");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜