Reputation: 1336
I don't want to send emails
to other users. I only want to open the launching activity
of Email
. I have tried it through different ways but every time send email(compose)
is opening. But i want to open Email
app only nothing else(Sent, outbox, spam, Trash etc).
My code is below
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);
}
Again, This code opens the send email to
(compose) option. But i want to open Email
app only nothing else(Sent, outbox, spam, Trash etc).
Upvotes: 9
Views: 9503
Reputation: 891
Building upon the answer by Vishal Nagvadiya, you should use makeMainSelectorActivity
instead of starting the activity directly:
try {
val intent = Intent
.makeMainSelectorActivity(
Intent.ACTION_MAIN,
Intent.CATEGORY_APP_EMAIL
)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
} (ignored: ActivityNotFoundException) {
// No activity found for the intent
}
In the JavaDocs of CATEGORY_APP_EMAIL
, it is stated:
NOTE: This should not be used as the primary key of an Intent, since it will not result in the app launching with the correct action and category. Instead, use this with
makeMainSelectorActivity(String, String)
to generate a main Intent with this category in the selector.
Upvotes: 0
Reputation: 1278
Use this code to open default Mail Application :
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();
}
Upvotes: 18