Calihog Calihog - 3 months ago 8
Android Question

Start another app directly, without showing the 'Open with..." dialogue?

I am wondering if it's possible to start another app with an intent, but directly - without showing the 'Open with..'dialogue.

In my case, I want to open a PDF file from my own application, but using Adobe Reader. This works just fine, but I want to start the reader directly, without displaying 'Open with..'.

When the button is clicked, I want to open Adobe Reader and directly load the file to view it. Is this possible?

Here is the code for my openPDF method

public void openPDF(View view) {
File externalFile = new File(Environment.getExternalStorageDirectory(), "Untitled.pdf");
if (externalFile.exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri path = Uri.fromFile(externalFile);
intent.setDataAndType(path, "application/pdf");
PackageManager pm = getPackageManager();
pm.getLaunchIntentForPackage("com.adobe.reader");
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities.size() > 0) {
startActivity(intent);
}
}
}

Answer