[英]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.