Can I click a button programmatically for a predefined intent?

AndroidButtonClickAndroid Intent

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

You can click a button programmatically by using the button.performClick() method.

Solution 2 - Android

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

Solution 3 - Android

button.callOnClick();

this one can also be used

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioninfoView Question on Stackoverflow
Solution 1 - AndroidNirav BhandariView Answer on Stackoverflow
Solution 2 - AndroidPeteHView Answer on Stackoverflow
Solution 3 - AndroidFlashView Answer on Stackoverflow