This appears to be due to the new restrictions on “package visibility” introduced in Android 11.
Basically, starting with API level 30, if you’re targeting that version or higher, your app cannot see, or directly interact with, most external packages without explicitly requesting allowance, either through a blanket QUERY_ALL_PACKAGES
permission, or by including an appropriate <queries>
element in your manifest.
Indeed, your first snippet works as expected with that permission, or with an appropriate <queries>
element in the manifest; for example:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
The information currently available isn’t terribly specific, but it does state:
The
PackageManager
methods that return results about other apps, such asqueryIntentActivities()
, are filtered based on the calling app’s<queries>
declaration
Though your example is using an Intent
method – i.e., resolveActivityInfo()
– that’s actually calling PackageManager
“query” methods internally. An exhaustive list of every method and functionality affected by this change might not be feasible, but it’s probably safe to assume that if PackageManager
is involved, you might do well to check its behavior with the new restrictions.