转自:http://blog.csdn.net/chanccie/article/details/8314951
一、根据包名判断应用是否存在
public boolean checkApplication(String packageName) {
if (packageName == null || “”.equals(packageName)){
return false;
}
try {
ApplicationInfo info = getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
二、判断Activity是否存在
Intent intent = new Intent();
intent.setClassName(“包名”, “类名”);
方法一:
if (getPackageManager().resolveActivity(intent, 0) == null) {
// 说明系统中不存在这个activity
}
方法二:
if(intent.resolveActivity(getPackageManager()) == null) {
// 说明系统中不存在这个activity
}
方法三:
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0);
if (list.size() == 0) {
// 说明系统中不存在这个activity
}