Android PackageManager:检查库 APK 是否已安装

发布于 2025-01-09 08:07:05 字数 892 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2025-01-16 08:07:05

正如您在 链接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 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文