在 Android Studio 中仅通过意图打开电子邮件应用程序
Open Email App only through intent in Android Studio
我不想发送 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
应用程序(已发送、发件箱、垃圾邮件、垃圾箱等)。
使用此代码打开默认邮件应用程序:
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();
}
我不想发送 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
应用程序(已发送、发件箱、垃圾邮件、垃圾箱等)。
使用此代码打开默认邮件应用程序:
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();
}