0
我有一臺藍牙服務器監聽筆記本電腦上的傳入連接。 Android是一個客戶端,希望連接到PC。Android(2.2.1)藍牙:HTC Wildfire:從Android連接到PC:每次都必須更改UUID?
怎麼了? 我可以第一次連接併發送數據到PC。當我關閉Android活動並重新啓動時,連接功能通過,但PC沒有註冊新的連接。當我嘗試發送數據,機器人系統日誌以下:
05-16 13:11:17.091:ERROR/BluetoothEventLoop.cpp(102):event_filter:收到的信號org.bluez.Device:從的PropertyChanged /組織/ bluez/30064/hci0/dev_50_63_13_CB_52_96
什麼可行? 如果我更改服務器的UUID,在服務器和客戶端上,它會在我第一次嘗試連接時再次運行。隨後的嘗試不起作用。
Server代碼:
/** Waiting for connection from devices */
private void waitForConnection() {
// retrieve the local Bluetooth device object
LocalDevice local = null;
StreamConnectionNotifier notifier;
StreamConnection connection = null;
// setup the server to listen for connection
try {
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
UUID uuid = new UUID("af29e59088cc11e1b0c40800200c9a56", false);
System.out.println(uuid.toString());
String url = "btspp://localhost:" + uuid.toString() + ";name=ThinBTClient";
notifier = (StreamConnectionNotifier)Connector.open(url);
} catch (Exception e) {
e.printStackTrace();
return;
}
// waiting for connection
while(true) {
try {
System.out.println("Wait Thread: Waiting for connection...");
connection = notifier.acceptAndOpen();
System.out.println("Got connection");
Thread processThread = new Thread(new ProcessConnectionThread(connection));
processThread.start();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
客戶端代碼:
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
UUID SPP_UUID = UUID.fromString("af29e590-88cc-11e1-b0c4-0800200c9a56");
try {
btSocket = device.createRfcommSocketToServiceRecord(SPP_UUID);
mBluetoothAdapter.cancelDiscovery();
btSocket.connect();
outStream = btSocket.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
任何想法?