【问题标题】:Android Intent (or code) to open email composer in (outlook, gmail)Android Intent(或代码)在(outlook,gmail)中打开电子邮件编辑器
【发布时间】:2018-08-07 15:37:48
【问题描述】:

我想知道如何在 gmail 或 Outlook 中打开撰写电子邮件的活动。到目前为止,我只知道要重定向到例如 gmail,但我也会打开“composer”(或其他)并添加一个电子邮件地址。我已经尝试过:

 intent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});

但不起作用

测试应用的完整源代码

 public class MainActivity extends AppCompatActivity {

private static final String GOOGLE_MAIL = "com.google.android.gm";
private static final String OUTLOOK = "com.microsoft.office.outlook";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    test(GOOGLE_MAIL);

}


private void test(String mail) {

    Intent intent = getPackageManager().getLaunchIntentForPackage(mail);
    intent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
    startActivity(intent);
}

}

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    你可以试试这个:

    protected void sendEmail() {
      Log.i("Send email", "");
    
      String[] TO = {"someone@gmail.com"};
      String[] CC = {"xyz@gmail.com"};
      Intent emailIntent = new Intent(Intent.ACTION_SEND);
      emailIntent.setData(Uri.parse("mailto:"));
      emailIntent.setType("text/plain");
    
    
      emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
      emailIntent.putExtra(Intent.EXTRA_CC, CC);
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
      emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
    
      try {
         startActivity(Intent.createChooser(emailIntent, "Send mail..."));
         finish();
         Log.i("Finished sending email...", "");
      } catch (android.content.ActivityNotFoundException ex) {
         Toast.makeText(MainActivity.this, 
         "There is no email client installed.", Toast.LENGTH_SHORT).show();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      • 2017-06-27
      • 2020-04-22
      • 2018-03-11
      相关资源
      最近更新 更多