android.content.pm.PackageManager$NameNotFoundException: com.android.chrome

Viewed 2865

I'm not able to fetch package info of google chrome app only in android 11 devices / API 30. Rest all devices working fine

Please check the below code mentioned.

PackageManager pm = context.getPackageManager();
    try {
        pi = pm.getPackageInfo("com.android.chrome", 0);
        value = pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.toString()
    }

Exception Thrown : android.content.pm.PackageManager$NameNotFoundException: com.android.chrome

Any help would be appreciated. Thanks

1 Answers

Problem Solved.. Introduction to Android 11, Google updated Security policy to access packages selectively and individually instead of fetching all packages.

For this need to add element in manifest.

https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

 <manifest package="com.example.game">
   <queries>
      <package android:name="com.example.store" />
      <package android:name="com.example.service" />
    </queries>
 </manifest>
Related