2010-05-20 181 views
2

我試圖模仿gilead的成功(here),但到目前爲止他的代碼在我的應用程序中失敗。我試過多個UUID,但沒有任何作用。當我運行sdptool records [address]我得到:Android SPP藍牙到非Android設備

$ sdptool records 00:12:F3:04:80:80 
sdptool records 00:12:F3:04:80:80 
Service Name: SPP 
Service RecHandle: 0x10001 
Service Class ID List: 
"Serial Port" (0x1101) 
Protocol Descriptor List: 
"L2CAP" (0x0100) 
"RFCOMM" (0x0003) 
Channel: 1 
Failed to connect to SDP server on 00:12:F3:04:80:80: Connection timed out 

它顯示設備上的通道1,所以我不明白爲什麼代碼不能正常工作。我正在運行Android 2.1。我無法以任何方式訪問其他設備,並且在調試tmpsock在調用.connect()之前具有所有正確的值。

我的代碼

public void test(BluetoothDevice d) throws Exception 
{ 
BluetoothSocket tmpsock = null; 
OutputStream out = null; 
InputStream in = null; 
int port = 1; 
Method m = d.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); 
tmpsock = (BluetoothSocket)m.invoke(d, port); 
Log.d("BT", "CONNECTING!!!!"); 
tmpsock.connect(); 
Log.d("BT", "CONNECTED!"); 
    ... 
} 

回答