skip to Main Content

enter image description here

the email intent code is completely run in the android mobile model provided by android studio but when I run the code in my personal phone its not work…
please answer ??

5

Answers


  1. Kotlin code,

    val selectorIntent = Intent(Intent.ACTION_SENDTO)
    selectorIntent.data = Uri.parse("mailto:")
    val emailIntent = Intent(Intent.ACTION_SEND)
    emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf<String>("mail id"))
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject")
    emailIntent.selector = selectorIntent
    startActivity(Intent.createChooser(emailIntent, "Send email..."))
    

    Java code,

    Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
    selectorIntent.setData(Uri.parse("mailto:"));
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"mail id"});
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    emailIntent.setSelector(selectorIntent);
    startActivity(Intent.createChooser(emailIntent, "Send email..."));
    
    Login or Signup to reply.
  2. Intent intEmail = new Intent(Intent.ACTION_SENDTO);
    intEmail.setType("plain/text");
    intEmail.setData(Uri.parse("mailto:"));
    intEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"receiver_email_address"});
                
     if (intEmail.resolveActivity(getPackageManager()) != null){
        startActivity(intEmail);
        }
    
    Login or Signup to reply.
  3. Don’t forget to set the type of intent so it will trigger email clients

       Intent email = new Intent(Intent.ACTION_SEND);  
        email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});  
        email.putExtra(Intent.EXTRA_SUBJECT, subject);  
        email.putExtra(Intent.EXTRA_TEXT, message);  
               
        //need this to prompts email client only  
        email.setType("message/rfc822");  
          
        startActivity(Intent.createChooser(email, "Choose an Email client :"));
    
      
    
    Login or Signup to reply.
  4. I tested the code of mayar hassan, it worked fine on my side. [on Samsung Android 8.1]

    The code:

    public class TestSentMail extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_sent_mail);
    
            Button button = findViewById(R.id.submitButton);
            button.setOnClickListener(view -> {
                submitOrder();
            });
        }
    
        private void submitOrder() {
            Intent intent = new Intent(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse("mailto:"));
            intent.putExtra(Intent.EXTRA_SUBJECT, "coffe order for tancolo");
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }
        }
    }
    

    The screenshot:

    sent email screenshot

    How to fix your problem

    In general, I think we should do these as below.

    1. Check the log in the Logcat panel in Android Studio, maybe there are exceptions.
    2. Added your debug code where you want to add.
    Login or Signup to reply.
  5. val i = Intent(Intent.ACTION_SEND)
        i.type = "message/rfc822"
        i.putExtra(Intent.EXTRA_EMAIL, arrayOf<String>("[email protected]"))
        i.putExtra(Intent.EXTRA_SUBJECT, "Feedback")
        i.putExtra(Intent.EXTRA_TEXT, "Text here...")
        try {
            startActivity(Intent.createChooser(i, "Send mail..."))
        } catch (ex: ActivityNotFoundException) {
            Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT)
                .show()
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search