Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 700
hemanth reddy Avatar asked Nov 13 '20 10:11

hemanth reddy


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>
like image 157
hemanth reddy Avatar answered Oct 26 '22 19:10

hemanth reddy