문제

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);
    }
}

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>

How can I do this?

도움이 되었습니까?

해결책

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);
    }

Hope that helps

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top