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
??}