Android open emailclient programmatically

后端 未结 5 836
小鲜肉
小鲜肉 2020-12-10 12:57

Is it possible to open an emailclient such as gmail when I click a button in my app?

相关标签:
5条回答
  • 2020-12-10 13:13
    Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                        "mailto", EMAIL_ADDRESS, null));
    

    up to date way of doing it

            i.putExtra(android.content.Intent.EXTRA_SUBJECT, SUBJECT);
            i.putExtra(android.content.Intent.EXTRA_TEXT, BODY);
            startActivity(Intent.createChooser(i, "Send email"));
    
    0 讨论(0)
  • 2020-12-10 13:14

    This Worked fine for me

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"mobiz@gmail.com"} );
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support: Speech to text App");
                    startActivity(Intent.createChooser(shareIntent, "Share "));
    
    0 讨论(0)
  • 2020-12-10 13:15

    You can simply use below code when for no attachment:

    Intent i = new Intent(Intent.ACTION_SENDTO);
    i.setData(Uri.parse("mailto:support@mailname.com")); 
    i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
    startActivity(Intent.createChooser(emailIntent, "Send feedback"));
    

    For details I recommend to visit: https://developer.android.com/guide/components/intents-common.html#Email

    0 讨论(0)
  • 2020-12-10 13:17

    Yes. You can launch it via Intents.

    Intent i = new Intent(Intent.ACTION_SEND);
    i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
    i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    i.putExtra(android.content.Intent.EXTRA_TEXT, text);
    startActivity(Intent.createChooser(i, "Send email"));
    
    0 讨论(0)
  • 2020-12-10 13:22

    If above code is not working then try this. Tested and working

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("vnd.android.cursor.item/email"); 
    intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{Constants.FEEBBACK_EMAIL_ADDRESS});
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
    startActivity(Intent.createChooser(intent, "Send mail using..."));
    
    0 讨论(0)
提交回复
热议问题