如何找到带有特定意图过滤器的所有软件包? [英] How can I find all the packages with a particular intent filter?

查看:74
本文介绍了如何找到带有特定意图过滤器的所有软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取所有已安装软件包的名称,这些软件包的名称均使用 com.mridang .为了做到这一点,我在以下代码片段的行中使用了一些东西:

I need to get the names of all the installed packages whose names being with com.mridang. In order to do this, I'm using something on the lines of the following snippet:

for (PackageInfo pkgPackage : mgrPackages.getInstalledPackages(0)) {
    if (pkgPackage.applicationInfo.packageName.startsWith("com.mridang.")) {
        System.out.println(pkgPackage.applicationInfo.packageName);
    }
}

我只需要获取包含以下意图过滤器 com.google.android.apps.dashclock.Extension 的服务的那些软件包的名称.

I need to only get the names of those packages which have a service containing the following intent filter com.google.android.apps.dashclock.Extension.

以下是示例包中清单文件的片段:

Here's a snippet of of the manifest files of on the example packages:

    <service
        android:name="com.mridang.storage.StorageWidget"
        android:icon="@drawable/ic_dashclock"
        android:label="@string/extension_name"
        android:permission="com.google.android.apps.dashclock.permission.READ_EXTENSION_DATA" >
        <intent-filter>
            <action android:name="com.google.android.apps.dashclock.Extension" />
        </intent-filter>

    </service>

我该怎么做?

推荐答案

您可以使用

You can do it with PackageManager#queryIntentServices

    Intent intent = new Intent("com.google.android.apps.dashclock.Extension");
    for (ResolveInfo info : mgrPackages.queryIntentServices(intent, 0)) {
        String packageName = info.serviceInfo.applicationInfo.packageName;
        // you can then filter by packageName.startsWith("com.mridang");
        Log.d("Packages", "package = " + packageName);
    }

希望有帮助

这篇关于如何找到带有特定意图过滤器的所有软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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