將targetSdkVersion設置為30(Android 11)後，執行android.content.pm.PackageManager$NameNotFoundException時得到packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)。
Android 11 changes how apps can query and interact with other apps that the user has installed on a device. Using the new element, apps can define the set of other apps that they can access. This element helps encourage the principle of least privilege by telling the system which other apps to make visible to your app, and it helps app stores like Google Play assess the privacy and security that your app provides for users.
If your app targets Android 11, you might need to add the element in your app’s manifest file. Within the element, you can specify apps by package name or by intent signature.
<manifest ...> ... <queries> <package android:name="com.target-package" /> </queries> ... <application ...> ... </manifest>
<manifest ...> ... <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> ... <application ...> ... </manifest>
NameNotFoundException when calling getPackageInfo on Android 11