check match intent

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(PACKAGE_NAME, ACTIVITY_CLASS);

// check if intent can launch
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfos.size() == 0) {
   return null;
} else {
   return intent;
}
相關文章
相關標籤/搜索