【问题标题】:Open Email App only through intent in Android Studio仅通过 Android Studio 中的意图打开电子邮件应用程序
【发布时间】:2020-08-02 23:20:58
【问题描述】:

我不想将emails 发送给其他用户。我只想打开Email 的launching activity。我已经通过不同的方式尝试过,但每次发送email(compose) 都是打开的。 但我只想打开 Email 应用程序(已发送、发件箱、垃圾邮件、垃圾箱等)。

我的代码在下面

Intent intent = new Intent(Intent.ACTION_SENDTO)
    .setData(Uri.parse("mailto:"));

//check if the target app is available or not

if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

同样,此代码打开send email to(compose) 选项。 但我只想打开 Email 应用程序(已发送、发件箱、垃圾邮件、垃圾箱等)。

【问题讨论】:

  • 您好,您的帐户为何被暂停?发生这种情况你做了什么?
  • 我有机会在 500 次重复后复习问题。但是我是无缘无故的跳过,这就是版主给我的原因。大声笑

标签: java android android-studio android-intent android-activity


【解决方案1】:

使用此代码打开默认邮件应用程序:

try {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_APP_EMAIL);
    this.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
    Toast.makeText(Dashboard.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-08
  • 2021-07-31
  • 1970-01-01
相关资源
最近更新 更多