Determines whether a broadcast receiver for the specified intent is registered on a process. - Android Android OS

Android examples for Android OS:Process

Description

Determines whether a broadcast receiver for the specified intent is registered on a process.

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import java.util.List;

public class Main {
    /**//from w ww .  ja  v a  2s.com
     * Determines whether a broadcast receiver for the specified intent is registered on a process.
     * @param process The process where to look for broadcast receivers.
     * @param intent The intent that the broadcast receiver should catch.
     * @param context The application context.
     * @return True if a matching broadcast receiver is registered on the process.
     */
    static boolean hasBroadcastReceiver(String process, Intent intent,
            Context context) {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> listeners = pm.queryBroadcastReceivers(intent, 0);
        for (ResolveInfo info : listeners) {
            if (info.activityInfo.processName.equals(process))
                return true;
        }
        return false;
    }
}

Related Tutorials