gpt4 book ai didi

android - 如何仅在手机上安装了与之相关的apk时才显示菜单选项

转载 作者:行者123 更新时间:2023-11-29 02:02:34 24 4
gpt4 key购买 nike

假设我有一个名为“显示”的菜单选项,我的应用程序 com.android.display 正在执行显示图片的任务。现在如果设备上没有安装 apk com.android.display,则菜单选项“display' 来了,但它没有用。所以我希望只有当这个 apk 安装在设备上时,才会出现 'display' 菜单选项。有什么方法可以在 Android 操作系统上实现这一点?

最佳答案

此特定解决方案在 Android How To on Google Sites

If you ever need to know if a particular app is installed on the user's device, you can use the PackageManager. From a Context class (e.g. an Activity or a Service) you can call getPackageManager(). This gives you a variety of methods, one of which is getPackageInfo(). Below is a method you might use. You might call it like this:

isAppInstalled("com.simexusa.campusmaps_full");

private boolean isAppInstalled(String uri) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}

关于android - 如何仅在手机上安装了与之相关的apk时才显示菜单选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11857561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com