3

The PackageManager.getPackageInfo(packageName, flags) method can be used to check whether a specific package has been installed. It either returns the PackageInfo or throws PackageManager.NameNotFoundException.

How to check if a library APK is installed? An example of the library APK is Trichrome Library: https://www.apkmirror.com/apk/google-inc/trichrome-library/trichrome-library-98-0-4758-101-release/trichrome-library-98-0-4758-101-3-android-apk-download/download/

After installation of this APK, calling PackageManager.getPackageInfo('com.google.android.trichromelibrary', 0) throws PackageManager.NameNotFoundException.

Looking via ADB, I see that once installed, it's not visible under pm list packages but it's visible under pm list libraries with the name "library:com.google.android.trichromelibrary".

Is there any way to determine programmatically whether the library has been installed?

Robert
  • 39,162
  • 17
  • 99
  • 152
vmayorow
  • 630
  • 5
  • 15

1 Answers1

3

As you can see in the source code of pm in this link, pm list libraries command uses PackageManager.getSystemSharedLibraryNames() which is documented here.

If this method is not working, there are also other methods in PackageManager to get info about shared libraries. As mentioned by @vmayorow, One of these methods is PackageManager.getSharedLibraries(0).

mahdi
  • 598
  • 5
  • 22
  • I have tested this method and it didn't returned the installed library name (I don't know why). But the method PackageManager.getSharedLibraries(0) returned the installed library! So I think your answer needs to be corrected to be selected. – vmayorow Feb 25 '22 at 06:21
  • 1
    @vmayorow `PackageManager` implementation might be device specific in some cases, and I suspect that is the reason for the method not working for you. I also updated the answer to include your solution. – mahdi Feb 26 '22 at 07:30