I need the button click of the intent ACTION_SEND. Here there is no need of displaying UI. Can I get the "Send" button click from the MMS-SMSProvider in Android?
Asked
Active
Viewed 8.7k times
3 Answers
277
You can click a button programmatically by using the button.performClick()
method.

laalto
- 150,114
- 66
- 286
- 303

Nirav Bhandari
- 4,550
- 6
- 32
- 59
-
1Hint: Reference your button using findViewById(R.id.your_button_id); – nortally Nov 23 '20 at 06:18
53
If your button includes any animation, you'll need to perform the click and then invalidate each step after performClick. Here's how:
button.performClick();
button.setPressed(true);
button.invalidate();
button.setPressed(false);
button.invalidate();
On occasion I've also had to introduce delay to get the animation to show. Like this:
//initiate the button
button.performClick();
button.setPressed(true);
button.invalidate();
// delay completion till animation completes
button.postDelayed(new Runnable() { //delay button
public void run() {
button.setPressed(false);
button.invalidate();
//any other associated action
}
}, 800); // .8secs delay time

PeteH
- 1,870
- 25
- 23
11
button.callOnClick();
this one can also be used

Flash
- 1,105
- 14
- 16
-
-
`callOnClick()` doesn't make a clicking sound which is what I needed. While `performClick()` makes a sound. – biinui Aug 02 '21 at 04:50