问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/20846972/how-can-i-find-all-the-packages-with-a-particular-intent-filter