Luis A. Florit
Luis A. Florit

Reputation: 2609

Check if there is an app listening to my intent

How to know if the intent I am going to publish is going to be answered in advance?

After building an intent, I tried this, which does not work:

Intent fc = ....
                
PackageManager manager = context.getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(fc, 0);            
startActivityForResult(fc, 1);

Despite the fact that list has 0 elements, an app was opened by the intent.

Upvotes: 3

Views: 153

Answers (2)

CommonsWare
CommonsWare

Reputation: 1006614

On Android 11 and higher, to use many (most?) methods on PackageManager, you need to have a <queries> element in your manifest, identifying the apps (or criteria for apps) that you want to find via PackageManager. Without that <queries> element, the package visibility rules will limit you results to your own app and some system apps.

Upvotes: 2

Yavor Mitev
Yavor Mitev

Reputation: 1508

Or, set MATCH_ALL to prevent any filtering of the results

public static final int MATCH_ALL = 131072;

There are more flags to try. Replace 0 with others.

https://developer.android.com/reference/android/content/pm/PackageManager#queryIntentActivities(android.content.Intent,%20int)

Upvotes: 0

Related Questions