我收到蓝牙配对请求,我只需按下确定按钮。我想通过代码来做到这一点。我该怎么办?我可以在ACTION_BOND_STATE_CHANGED事件中做到这一点吗?
如果我应该使用.performClick(),我怎样才能从配对蓝牙对话框中获得对ok按钮的引用?
到目前为止,我在onReceive功能上有一个BroadCast接收器:
if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
int prevBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1);
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.i(TAG, "bond state changed");
Log.i(TAG, "device:" + device.getName());
Log.i(TAG, "prev state:" + prevBondState);
Log.i(TAG, "curr state:" + bondState);
if (prevBondState == BluetoothDevice.BOND_BONDING) {
if (bondState == BluetoothDevice.BOND_BONDED) {
Globals.sendStatus("bluetooth", device.getName() + " pairing successful");
Log.i(TAG, device.getName() + " pairing successful");
}
} else if (prevBondState == BluetoothDevice.BOND_BONDED) {
if (bondState == BluetoothDevice.BOND_NONE) {
Log.i(TAG, device.getName() + " unpairing successful");
Globals.sendStatus("bluetooth", device.getName() + " unpaired");
}
}
}