Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check whether email client installed on device

Tags:

android

I need to check whether email client is installed on a device or not. I have used the following code but it does not work for me.

public boolean isIntentAvailable() {
    final PackageManager packageManager = getApplicationContext().getPackageManager();
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_META_DATA);
    return list.size() > 0;
} 
like image 592
user1503346 Avatar asked Sep 27 '12 08:09

user1503346


People also ask

Is Gmail app an email client?

A Gmail client is an email client specifically for Gmail users. You likely already use at least one Gmail client — if you use IMAP to read your Gmail messages via the email app on your Android, iPhone, or other mobile device, you're already using a Gmail client.


3 Answers

Use this, works for me :

public static boolean isMailClientPresent(Context context){
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/html");
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);

    if(list.size() == 0)
        return false;
    else 
        return true;
}
like image 113
Nitin Avatar answered Oct 22 '22 08:10

Nitin


For email client, specifically, you should use:

intent.setType("message/rfc822");

instead of:

intent.setType("text/html");
like image 40
eyal Avatar answered Oct 22 '22 08:10

eyal


use this method:

    private fun sendEmail(to: Array<String>) {
        val intent = Intent(Intent.ACTION_SENDTO)
        intent.data = Uri.parse("mailto:") // only email apps should handle this
        intent.putExtra(Intent.EXTRA_EMAIL, to)
//        intent.putExtra(Intent.EXTRA_SUBJECT, subject)
        if (intent.resolveActivity(requireContext().packageManager) != null) {
            startActivity(intent)
        }
    }

To be able to check for email clients when targeting api 30, add "queries" to the Manifest:

<queries>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="*" />
    </intent>
</queries>
like image 45
fullmoon Avatar answered Oct 22 '22 09:10

fullmoon