2012-07-24 166 views
3

我的Android設備正試圖通過藍牙連接到傳感器。Android藍牙設置功能

作爲普通藍牙設備,我將需要務實設立P​​IN碼(通常爲0000或1234)

爲傳感器側,因爲它是無聲,不會彈出請求的對話。

我在Android開發站點沒有找到任何相關線索。

有沒有人可以告訴我,如果有任何方法可以做到這一點?

回答

5

要設置PIN碼,您可以通過反射來調用BluetoothDevice類中的隱藏方法setPin(byte[])

實施例:

try { 
    Log.d("setPin()", "Try to set the PIN"); 
    Method m = device.getClass().getMethod("setPin", byte[].class); 
    m.invoke(device, pin); 
    Log.d("setPin()", "Success to add the PIN"); 
} catch (Exception e) { 
    Log.e("setPin()", e.getMessage()); 
} 

哪裏device是您的BluetoothDevicepin一個byte[]數組,它包含藍牙設備引腳。

但我認爲,您更願意使用方法setPasskey(int)。這對您來說會更容易,因爲您要設置「0000」或「1234」等密碼。

[更新]

上一頁源鏈接是死的和階級已被更新。顯然setPasskey不存在了。按照下面的文檔鏈接查找您需要的信息。

來源:BluetoothDevice Android documention