Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何跳过android中发送邮件的选择器对话框_Android_Email_Gmail_Sendmail - Fatal编程技术网

如何跳过android中发送邮件的选择器对话框

如何跳过android中发送邮件的选择器对话框,android,email,gmail,sendmail,Android,Email,Gmail,Sendmail,我得到了选择电子邮件客户端(Gmail、电子邮件等)的弹出窗口,但我想跳过它,直接通过Gmail发送 protected void sendEmail() { String[] recipients = { recieverId.getText().toString() }; Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); email.setType("message/r

我得到了选择电子邮件客户端(Gmail、电子邮件等)的弹出窗口,但我想跳过它,直接通过Gmail发送

protected void sendEmail() {        
   String[] recipients = { recieverId.getText().toString() };
   Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));

   email.setType("message/rfc822");

   email.putExtra(Intent.EXTRA_EMAIL, recipients);
   email.putExtra(Intent.EXTRA_SUBJECT, mailSubject.getText().toString());
   email.putExtra(Intent.EXTRA_TEXT, mailBody.getText().toString());

   try {
      startActivity(Intent.createChooser(email,
         "Choose an email client from..."));
   } catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(getApplicationContext(),
         "No email client installed.", Toast.LENGTH_LONG).show();
   }
}

只需省略
createChooser
和硬编码Gmail意图,如下所述:

在intent中设置类名对我很有用。无需添加选择器。要通过office邮件客户端发送电子邮件,您可以添加发件人(出于目的)或从gmail帐户组成部分的邮件ID列表中选择发件人

public void sendGmail(Activity activity, String subject, String text) {
    Intent gmailIntent = new Intent();
    gmailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
    gmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    gmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    try {
      activity.startActivity(gmailIntent);
    } catch(ActivityNotFoundException ex) {
      // handle error
    }
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent emailIntent = new Intent();
    emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");// Package Name, Class Name
    emailIntent.setData(Uri.parse("mailto:")); 
    emailIntent.setType("text/plain"); 
    emailIntent.putExtra(Intent.EXTRA_EMAIL, "Your Sender Mail ID"); 
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject"); 
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Body of the Email "); 
    startActivity(emailIntent);
}

    You can get the Package name via adb shell Command:
    pm list packages -f
emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");// Package Name, Class Name