2017-08-27 91 views
0

First方法創建套接字拋出IOException異常:的BluetoothSocket#Connect是鎖定線後,同時

try { 
    socket = device.createRfcommSocketToServiceRecord(BSERVICE_UUID) 
} catch(e: Exception) { 
    e.printStackTrace() 
} 

第二條本辦法創造插座:

try { 
    socket = device.createInsecureRfcommSocketToServiceRecord(BSERVICE_UUID) 
} catch(e: Exception) { 
    e.printStackTrace() 
} 

第三種方法創建套接字:

try { 
    socket = createRfcommSocket(device) 
} catch(e: Exception) { 
    e.printStackTrace() 
} 

用createRfcommSocket(設備)定義爲:

private fun createRfcommSocket(device: BluetoothDevice): BluetoothSocket? { 
    val method = device::class.java.getMethod("createRfcommSocket", Int::class.javaPrimitiveType) 
    return method.invoke(device, 1) as BluetoothSocket? 
} 

這些都是在我實際調用BluetoothSocket#connect()之前執行的非空引用。線程被凍結了一會兒,然後 - 拋出一個異常:

java.io.IOException: read failed, socket might closed or timeout, read ret: -1 
W/System.err:  at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:581) 
W/System.err:  at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:558) 
W/System.err:  at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:374) 

與這個問題有關的所有數據:

設備是這裏的主題,通過BluetoothAdapter#startDiscovery(發現)方法與正確的廣播接收機註冊。該過程如下所示:在本地緩存設備,然後在收到ACTION_DISCOVERY_FINISHED Intent之後 - 開始調用BluetoothDevice#fetchUuidsWithSdp()。上述問題的潛在原因是在ACTION_UUID Intent中,我接收到一個空值,作爲從意圖中用關鍵BluetoothDevice.EXTRA_UUID提取的UUID數組對象。

在API級別19的三星Galaxy Tab S上測試。沒有固定。通過BLE,它可以在相同的設備上正常工作。

沒有UUID可以工作:標準「00001101-0000-1000-8000-00805F9B34FB」或設備文檔中都沒有指出任何可能的可能。

有趣的是,基於反射的解決方案給出了同樣的問題。

UPD:從日誌中發現另一件事。在連接功能後幾秒鐘獲取調用我得到這個:

D/BluetoothSocket: SecProductFeature_BLUETOOTH.SEC_PRODUCT_FEATURE_BLUETOOTH_IT_POLICY_FEATURE = true 
W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback 

第一行中的谷歌沒有結果,不知何故,也許這是我的問題的原因是什麼?

回答

0

已關閉,該設備不支持Bluetooth Classic,並允許僅在BLE的頂部創建交互。