I don't know if this questing ever asked before, tried to search and found nothing.

Is that possible to search and display installed package by checking it's manifest if contains specific intent filter?

Ex: I want to display installed package that contains custom Intent Filter on it's manifest

<intent-filter>
      <action android:name="com.example.one" />
</intent-filter>

As a sample, then if application is exist, I want to make a text "Application Exist" on a textview

if (...//checking if application exist or not) {
      textview.setText("Application Exist");
}
else {
...
}
有帮助吗?

解决方案

Check out queryIntentActivities()

So you create an intent with the correct filter matching discriminators on it.

Intent intent = new Intent("my_awesome.package.hasa.custom.ACTION!");
intent.addCategory("typingisfunfunfun");
intent.setData(Uri.parse("data://foo/bar"));
PackageManager pm = getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
if(resolveInfo.isEmpty()) {
  Log.i("NoneResolved", "No Activities");
} else {
  Log.i("Resolved!", "There are activities" + resolveInfos);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top