[英]Simulate click on ok button android
我收到蓝牙配对请求,只需要按OK按钮即可。 我想通过代码做到这一点。 我该怎么办? 我可以在ACTION_BOND_STATE_CHANGED事件中做到这一点吗?
如果我应该使用.performClick()进行操作,如何从配对蓝牙对话框中获取对“确定”按钮的引用?
到目前为止,我有一个BroadCast接收器,它在onReceive函数上:
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");
}
}
}
您可以尝试performClick ()方法。 这将触发与按钮关联的onClickListener
。
myButton.performClick();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.