How to check if an intent can be handled from some activity? How to check if an intent can be handled from some activity? android android

How to check if an intent can be handled from some activity?


edwardxu's solution works perfectly for me.

Just to clarify a bit:

PackageManager packageManager = getActivity().getPackageManager();if (intent.resolveActivity(packageManager) != null) {    startActivity(intent);} else {    Log.d(TAG, "No Intent available to handle action");}


PackageManager manager = context.getPackageManager();List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);if (infos.size() > 0) {    //Then there is an Application(s) can handle your intent} else {    //No Application can handle your intent}

Have you tried this intent?

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(yourFileHere));


if (intent.resolveActivity(getPackageManager()) == null) {    // No Activity found that can handle this intent. }else{    // There is an activity which can handle this intent. }