Returns true if the given intent can be handled on this device - Android Intent

Android examples for Intent:Open App

Description

Returns true if the given intent can be handled on this device

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import android.support.annotation.NonNull;

import java.util.List;

public class Main {
    /**// www  .  ja va  2s.  c  om
     * Returns true if the given intent can be handled on this device
     * @param context
     * @param intent
     * @return
     */
    public static boolean canHandleIntent(@NonNull Context context,
            Intent intent) {
        PackageManager packageManager = context.getPackageManager();
        List<ResolveInfo> resolveInfo = packageManager
                .queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
        return resolveInfo.size() > 0;
    }
}

Related Tutorials