Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Email App only through intent in Android Studio

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).

like image 405
Shoaib Khalid Avatar asked Jan 01 '23 03:01

Shoaib Khalid


1 Answers

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();
}
like image 124
Vishal Nagvadiya Avatar answered Jan 02 '23 18:01

Vishal Nagvadiya