How to see if Intent is available:
-
Try calling Intent and deal with
ActivityNotFoundException
if it isn’t availableIntent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(OpenPdf.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); }
or
-
Query the Package Manager to see if it is ahead of time:
PackageManager packageManager = getPackageManager(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setType("application/pdf"); List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { intent.setDataAndType(path, "application/pdf"); startActivity(intent); }
How to pass parameters to an application or know its capabilities: