Android PackageManager:检查库 APK 是否已安装
PackageManager.getPackageInfo(packageName, flags)
方法可用于检查特定包是否已安装。它要么返回 PackageInfo,要么抛出 PackageManager.NameNotFoundException。
如何检查库 APK 是否已安装?库 APK 的一个示例是 Trichrome 库: 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/
安装此 APK 后,调用PackageManager.getPackageInfo('com.google.android.trichromelibrary', 0)
抛出 PackageManager.NameNotFoundException
。
通过 ADB 查看,我发现安装后,它在 pm list packages
下不可见,但在 pm list templates
下可见,名称为“library:com.google.android.三色图书馆”。
有什么方法可以以编程方式确定该库是否已安装?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您在 链接,
pm list links
命令使用PackageManager.getSystemSharedLibraryNames()
,该记录已记录此处。如果此方法不起作用,PackageManager 中还有其他方法可以获取有关共享库的信息。正如 @vmayorow 所提到的,这些方法之一是
PackageManager.getSharedLibraries(0)
。As you can see in the source code of
pm
in this link,pm list libraries
command usesPackageManager.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 isPackageManager.getSharedLibraries(0)
.