I receive a bluetooth pairing request and i only need to press the ok button. I want to do this by code. How should i do it? I can make this in the ACTION_BOND_STATE_CHANGED event?
If i should do it with .performClick() how can i get a reference to the ok button from the pairing bluetooth dialog?
Until now i have a BroadCast Receiver and this on the onReceive function:
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");
}
}
}