Utility method to detect whether an Email app is installed, for conditionally enabling/disabling email links. - Android App

Android examples for App:App Install

Description

Utility method to detect whether an Email app is installed, for conditionally enabling/disabling email links.

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;

import java.util.List;

public class Main {
    /**/*from   w w w.  j  ava2 s.  c  o  m*/
     * Utility method to detect whether an Email app is installed,
     * for conditionally enabling/disabling email links.
     * @param context Context of the calling app.
     * @return True if an Email app exists, false otherwise.
     */
    public static boolean mailAppExists(Context context) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:test@wikimedia.org"));
        List<ResolveInfo> resInfo = context.getPackageManager()
                .queryIntentActivities(intent, 0);
        return resInfo.size() > 0;
    }
}

Related Tutorials