Android 是怎么判断某个APK文件是否已经安装
答案:4 悬赏:70 手机版
解决时间 2021-03-04 05:08
- 提问者网友:那叫心脏的地方装的都是你
- 2021-03-03 15:50
最近在做一个项目要判断某个APK是否在应用列表中存在,我想知道Androud自带的那个安装的提醒的功能是怎么实现的
最佳答案
- 五星知识达人网友:末日狂欢
- 2021-03-03 16:23
Android系统中,判断应用有无安装有两种方式:
1.根据包名判断,以下为判断代码:
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName))
return false;
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
2. 根据Intent判断,以下为判断代码:
public boolean checkApkExist(Context context, Intent intent) {
List list = context.getPackageManager().queryIntentActivities(intent, 0);
if(list.size() > 0){
return true;
}
return false;
}
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName)) return false;
try {
ApplicationInfo info = context.getPackageManager() .getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true;
} catch (NameNotFoundException e) { return false; }
}
public boolean checkApkExist(Context context, Intent intent) {
List list = context.getPackageManager()
.queryIntentActivities(intent, 0);
if (list.size() > 0) {
return true;
}
return false;
}
1.根据包名判断,以下为判断代码:
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName))
return false;
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
2. 根据Intent判断,以下为判断代码:
public boolean checkApkExist(Context context, Intent intent) {
List
if(list.size() > 0){
return true;
}
return false;
}
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName)) return false;
try {
ApplicationInfo info = context.getPackageManager() .getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true;
} catch (NameNotFoundException e) { return false; }
}
public boolean checkApkExist(Context context, Intent intent) {
List
.queryIntentActivities(intent, 0);
if (list.size() > 0) {
return true;
}
return false;
}
全部回答
- 1楼网友:舍身薄凉客
- 2021-03-03 19:34
系统应该是检查签名的吧!不清楚!
- 2楼网友:迷人又混蛋
- 2021-03-03 18:16
判断某个apk文件是否已经安装 privateboolean 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; } if(isappinstalled("com.yourpackage.package")) { //app installed } else { //app not installed }
- 3楼网友:枭雄戏美人
- 2021-03-03 17:33
因为我的APK名称和安装后的应用名称是不一样的 所以这种办法不能判断APK是否已经安装了的 我现在想知道的就是Android自己是怎么判断的? 到eoeAndroid网站查看回答详情>>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯