我正在尝试获取处理android.intent.action.BOOT_COMPLETED
其他应用程序的接收器列表。
我只能通过以下方式获取具有该操作的应用:
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));
}
我可以使用以下代码获取接收器列表:
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
。有没有办法可以获得这些信息?
答案 0 :(得分:17)
我为人们重新格式化了。使用此并感谢您提出问题。
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);
}
}