Domanda

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 {
...
}
È stato utile?

Soluzione

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);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top