1

Bluetoothペアリングダイアログが表示されるたびに「ペアリングボタン」を強制的にクリックする方法はありますか?

ここに画像の説明を入力

4

1 に答える 1

3

ペアリング ダイアログにアクセスする方法はわかりませんが、次の方法でペアリングを「強制」することができました。

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 で動作しました (新しいリリースで動作するかどうかはわかりません)。

于 2013-10-26T19:22:00.833 に答える