0

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");
                }
            }
        }
Iulian932
  • 13
  • 3

1 Answers1

1

You can try performClick() method. This will fire the onClickListener associated with the button.

myButton.performClick();
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
  • But how can i get a reference to the ok button from the pairing request dialog? – Iulian932 Jul 22 '14 at 13:36
  • @Iulian932 could you show some code? Then I can suggest some measures if I can think of any. There could be some interfaces provided by the platform for such events inside broadcast receiver I guess – Illegal Argument Jul 22 '14 at 13:39
  • @Iulian932 http://stackoverflow.com/questions/7337032/how-can-i-avoid-or-dismiss-androids-bluetooth-pairing-notification-when-i-am-do and http://stackoverflow.com/questions/17168263/how-to-pair-bluetooth-device-programmatically-android try these I havenot used this so I cant be more helpful – Illegal Argument Jul 22 '14 at 13:48