我知道有很多這樣的問題,但沒有一個能夠解決我的問題。我試圖在兩個設備之間以編程方式實現藍牙配對。我能夠配對設備,但問題是,它需要用戶按下我不想在我的應用程序中的按鈕。我希望他們在沒有任何用戶交互的情況下進行連接,或者如果這不可行,它應該只請求一個設備按下配對按鈕並且應該配對。我有一臺三星電視,其工作原理是當我嘗試將我的Android手機的藍牙與它連接時。在我的手機上彈出一個雙引腳請求,當我配對時它會配對,但不會在電視上顯示任何內容而且他們倆都是配對的。我需要在我的應用程序中實現這一點。我已經試過這段代碼,但它沒有取得密碼,並且連接它仍然要求輸入密碼。如何在沒有用戶交互的情況下以編程方式配對藍牙設備?
public void setBluetoothPairingPin(BluetoothDevice device)
{
byte[] pinBytes = convertPinToBytes("0000");
try {
Log.d(TAG, "Try to set the PIN");
Method m = device.getClass().getMethod("setPin", byte[].class);
m.invoke(device, pinBytes);
Log.d(TAG, "Success to add the PIN.");
try {
device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
Log.d(TAG, "Success to setPairingConfirmation.");
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e(TAG, e.getMessage());
e.printStackTrace();
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
}
}
我一直在尋找了近一個星期now.Any想法的解決方案/建議,以實現上述將非常感激。
是兄弟,我已經嘗試過這...幫助不列入它 – 2015-03-03 10:50:24