Issue
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?
Solution
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)
.
Answered By - mahdi
Answer Checked By - Mildred Charles (JavaFixing Admin)