Android: open pdf from my application using the built-in PDF viewer

This was my original question:

I want to open a pdf file in my application using the built-in android application to view pdf, but I do not know how to start other applications. I am sure that I have to start working with the call, I just do not know how to determine the application im opening and how to transfer the file to this particular application.

Who has a key?

I just found out that the pdf viewer application that I have on my phone is actually made by HTC, and that Adobe has hardly released an Android viewer program for Android (which is great). So, the new question is this: how can I verify that the user has installed adobe viewer, and then how to open the file in this application from my application?

+27
android pdf workflow-activity
May 26 '10 at 19:29
source share
8 answers

AFAIK, Adobe has not documented any public Intents that they want developers to use.

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

+16
May 26 '10 at 20:52
source share
— -

You can programmatically determine if a suitable application exists on a user 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 } 
+38
May 21 '12 at 16:37
source share
 private void loadDocInReader(String doc) throws ActivityNotFoundException, Exception { try { Intent intent = new Intent(); intent.setPackage("com.adobe.reader"); intent.setDataAndType(Uri.parse(doc), "application/pdf"); startActivity(intent); } catch (ActivityNotFoundException activityNotFoundException) { activityNotFoundException.printStackTrace(); throw activityNotFoundException; } catch (Exception otherException) { otherException.printStackTrace(); throw otherException; } } 
+6
Oct 31 '11 at 11:27
source share
  FileFinalpath = SdCardpath + "/" + Filepath + Filename; File file = new File(FileFinalpath); if (file.exists()) { Uri filepath = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(filepath, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (Exception e) { alert.showAlertDialog(PDF_Activity.this, "File Not Started...","File Not Started From SdCard ", false); Log.e("error", "" + e); } } else { alert.showAlertDialog(PDF_Activity.this, "File Not Found...","File Not Found From SdCard ", false); } 
+3
Apr 04 '13 at 5:42 on
source share

Although this is a fairly old topic, here is a solution for opening a PDF file located in a folder with a folder with an external application for reading PDF files. It uses a custom content provider: https://github.com/commonsguy/cwac-provider

Using this, you can define any file to be provided from assets / or res / raw / folder.

Give it a try! The best and easiest solution I've found so far.

+2
Mar 03 '14 at 15:34
source share

I also ran into the same problem when I tried to display PDF on an Android device and finally ended up with a solution (integration of a third-party PDF library)

https://github.com/JoanZapata/android-pdfview

while I tested several libraries for the ones listed below that also work,

https://github.com/jblough/Android-Pdf-Viewer-Library

& mupdf, which comes with the ndk flavor ( https://code.google.com/p/mupdf/downloads/detail?name=mupdf-1.2-source.zip&can=2&q= ), and you need to extract it using the NDK, and then use it in the application as jar or java, etc. good article to explain the use of this library @ http://dixitpatel.com/integrating-pdf-in-android-application/

+1
Aug 17 '15 at 10:25
source share

Android has a built-in infrastructure from Android 5.0 / Lollipop, it is called PDFRenderer . If you can assume that your users have Android 5.0, this is probably the best solution.

There is an official example on the Google developer site:

http://developer.android.com/samples/PdfRendererBasic/index.html

It does not support annotation or other more complex functions; for those who have really returned to using intent to open a full application or insert an SDK, such as mupdf .

(Disclaimer: I rarely work on mupdf.)

+1
Apr 11 '16 at 18:37
source share

In addition to those marked as an answer, you will need these permissions in the manifest.xml file

**

 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

**

-one
Dec 21 '16 at 12:38
source share



All Articles