如何查找我的 Android 设备上是否存在特定软件包?
如何查找我的 Android 设备上是否存在特定的软件包或应用程序,例如:com.android.abc
?
How can I find whether a particular package or application, say: com.android.abc
, exists on my Android device?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用包名称调用以下任意方法。
Call any of the below method with the package name.
不使用 try-catch 块或迭代一堆包:
Without using a try-catch block or iterating through a bunch of packages:
Kotlin
编辑:扩展函数
Kotlin
Edit: Extension Function
我们可以这样检查:
Make method for package check!此功劳归于“Kavi”https://stackoverflow.com/a/30708227/6209105
}
We can check like this:
Make method for package check ! this credit goes to "Kavi" https://stackoverflow.com/a/30708227/6209105
}
您应该使用
PackageManager
的名为getInstalledPackages()
获取所有已安装软件包的列表并搜索您感兴趣的软件包。请注意,软件包名称位于PackageInfo.packageName
字段。You should use
PackageManager
's function calledgetInstalledPackages()
to get the list of all installed packages and the search for the one you are interested in. Note that package name is located inPackageInfo.packageName
field.由于某些设备报告“getInstalledPackages”可能会导致 TransactionTooLargeException(请检查 此处,此处和此处),我认为您也应该有一个后备方案,就像我在下面所做的那样。
此问题本应在 Android 5.1 上得到修复(请阅读此处),但是一些人仍然报道了此事。
Since some devices have reported that the "getInstalledPackages" can cause TransactionTooLargeException (check here, here and here), I think you should also have a fallback like I did below.
This issue was supposed to be fixed on Android 5.1 (read here), but some still reported about it.
如果您只想使用 adb:
它将列出所有已安装的软件包。
If you just want to use adb:
it will list all installed packages.
您可以使用 pm.getPackageUid() 而不是迭代 pm.getInstalledApplications()
You can use pm.getPackageUid() instead of iterating over the pm.getInstalledApplications()
根据Android 11中的包可见性过滤更改,您需要添加此权限您的清单能够列出已安装的应用程序:
但 Google 不建议使用这种方式。您应该使用
标签代替:在您的代码中:
According to the Package visibility filtering changes in Android 11, you need to add this permission to your manifest to be able to list installed apps:
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
but Google doesn't recommend to use this way. You should use
<queries>
tag instead:And in your code: