获取意图过滤器的接收器 [英] Get intent filter for receivers

查看:102
本文介绍了获取意图过滤器的接收器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让接收器可以处理 android.intent.action.BOOT_COMPLETED 其他应用程序的列表。

I am trying to get a list of receivers that handle android.intent.action.BOOT_COMPLETED for other applications.

我可以只与这方面的行动的应用程序:

I can get only the apps with that action with this:

final PackageManager pm = getPackageManager();
final Intent intent = new Intent("android.intent.action.BOOT_COMPLETED");
final List<ResolveInfo> activities = pm.queryBroadcastReceivers(intent, 0);
for (ResolveInfo ri : activities) {
    Log.i(TAG, "app name: " + ri.loadLabel(pm));
}

我可以接收这个code的清单:

I can get a list of receivers with this code:

final List<PackageInfo> packs = pm.getInstalledPackages(PackageManager.GET_RECEIVERS);
for (final PackageInfo p : packs) {
    ActivityInfo[] receivers = p.receivers;
    if (receivers != null) {
        for (ActivityInfo ai : receivers) {
            Log.i(TAG, "receiver: " + ai.name);
        }
    }                   
}

在我得到的接收器,我不能告诉的意图过滤器/动作是什么。如果一个应用程序有两个接收器,我需要知道哪一个手柄 android.intent.action.BOOT_COMPLETED 。有没有一种方法可以让我得到这个信息?

After I get the receivers I cannot tell what the intent-filter/action is. If an app has two receivers I need to know which one handles android.intent.action.BOOT_COMPLETED. Is there a way I can get this info?

推荐答案

我重新格式化的人。使用此,感谢的问题。

I reformatted for people. Use this and thanks for question.

PackageManager packageManager = getPackageManager();
List<String> startupApps = new ArrayList<String>();
Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);
List<ResolveInfo> activities = packageManager.queryBroadcastReceivers(intent, 0);
for (ResolveInfo resolveInfo : activities) {
    ActivityInfo activityInfo = resolveInfo.activityInfo;
    if (activityInfo != null) {
        startupApps.add(activityInfo.name);
    }
}

这篇关于获取意图过滤器的接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆