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
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;
}
因为我的APK名称和安装后的应用名称是不一样的 所以这种办法不能判断APK是否已经安装了的 我现在想知道的就是Android自己是怎么判断的? 到eoeAndroid网站查看回答详情>>
到/system/data下查一下有没有这个apk