skip to Main Content

trying to use Email intent on emulator logged in to Gmail on emulator but still, it is not connecting to Gmail.

Intent email = new Intent(Intent.ACTION_SENDTO);
        email.setData(Uri.parse("mailto:")); // only email apps should handle this
        email.putExtra(Intent.EXTRA_SUBJECT, "Your Order");
        email.putExtra(Intent.EXTRA_TEXT,pricemessage);
        if (email.resolveActivity(getPackageManager()) != null)
        {
            startActivity(Intent.createChooser(email, "Send Mail Using :"));
        }

2

Answers


  1. You can easily send email in android via intent. You need to write few lines of code only as given below

    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/cfr893");  
      
    startActivity(Intent.createChooser(email, "Choose an Email client :"));
    
    Login or Signup to reply.
  2. When I copied your code, it warned that Query Permission Needed. So, add the below code outside of tag in your manifest.xml file.

    <queries>
        <intent>
            <action android:name="android.intent.action.SENDTO" /><data android:scheme="*" />
            </intent>
    </queries>
    

    It works for me after adding it. Let me know if it works for you too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search