星期五, 9月 11, 2009

Android中如何檢查第三方Package是否有安裝?

第一個方法:
public static boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}

第二個方法:

透過Intent.resolveActivity(),PackageManager.resolveActivity()這兩個API來作,作法都大同小異。


Reference: [1] [2]

沒有留言: