2013-10-22 37 views

回答

2

我不知道怎麼去獲得配對對話,但我能「迫使」配對以下列方式:

1)註冊的動作一個BroadcastReceiver:

android.bluetooth.device.action.PAIRING_REQUEST 

2)一旦接收到動作, 「力」 的PIN使用反射:

String DEVICE_PIN = "12345"; 

final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 

if (intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")) { 
    byte[] pin = (byte[]) BluetoothDevice.class.getMethod("convertPinToBytes", String.class).invoke(BluetoothDevice.class, ARDUINO_PIN); 
    BluetoothDevice.class.getMethod("setPin", byte[].class).invoke(device, pin); 
} 

它適用於GB和ICS(不知道它是否適用於較新的版本)。

+0

我知道這種方法,但我想知道如何訪問配對對話無論如何感謝您的回覆。 –