Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: open a pdf from my app using the built in pdf viewer

This was my original question:

I want to be able to open a pdf file in my app using the android's built in pdf viewer app, but i dont know how to start other apps. I'm sure i have to call start activity, i just dont know how to identify the app im opening and how to pass the file to that specific app.

Anyone have a clue?

I just learned that the pdf viewer i have on my phone is actually made by HTC and that Adobe just barely released their android pdf viewer (which is great). So the new question is this: how do i verify that the user has installed adobe's viewer, and then how do i open the file in that app from my app?

like image 491
mtmurdock Avatar asked May 26 '10 19:05

mtmurdock


People also ask

How do I change which app opens PDF files?

Go to Settings. Go to Apps. Select the other PDF app, that always open up automatically. Scroll down to "Launch By Default" or "Open by default".

How do I change the default PDF viewer on my Android?

How do I change the default 'open with' on Android? Go to Settings > Apps > Select the default open with app > Clear defaults. Now, the next time you open a PDF file, select the app you would like to set as default 'open with' and select Remember my choice or Always option.

Does Android have a built in PDF reader?

Android has a built in framework from Android 5.0 / Lollipop, it's called PDFRenderer.


2 Answers

You can programmatically determine whether a suitable application exists on the user's device, without catching exceptions.

Intent intent = new Intent(Intent.ACTION_VIEW,         Uri.parse("path-to-document")); intent.setType("application/pdf"); PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); if (activities.size() > 0) {     startActivity(intent); } else {     // Do something else here. Maybe pop up a Dialog or Toast } 
like image 77
Karakuri Avatar answered Sep 24 '22 22:09

Karakuri


AFAIK, Adobe has not documented any public Intents it wants developers to use.

You can try an ACTION_VIEW Intent with a Uri pointing to the file (either on the SD card or MODE_WORLD_READABLE in your app-local file store) and a MIME type of "application/pdf".

like image 42
CommonsWare Avatar answered Sep 20 '22 22:09

CommonsWare