0

I need a pointer to a (preferably free) PDF viewer app that I can invoke on a file or URL link via a startActivity on an Intent. I know that there is no real standard - I have one phone that came with OpenOffice that can read local PDF files, and one phone that has no built-in PDF reader.

What I want is the name of an application that I can suggest to my users to download from the market that is a PDF viewer that I can invoke by configuring an Intent and calling startActivity. I would make this suggestion when I intercept a URL to a pdf file, and discover that the application is not yet installed. Although ugly, this is better than the blank screen they get now because the built in browser doesn't do PDF.

I already installed Adobe's PDF viewer but it is not showing up in the package manager as being a candidate to handle PDF files.

I have used the technique suggested in SO:how-to-render-pdf-in-android to examine the candidate activities for a URL based PDF link and a local file PDF link and see that the com.android.browser.Browser is always invoked for http:// URL links; a URL of "file.pdf" causes OpenOffice to be selected on one phone and nothing on the other phone. Adobe's PDF viewer is not a candidate for either approach.

I tried the Google Docs viewer approach (as suggested in SO:android-load-pdf-pdf-viewer but that leaves a lot to be desired, especially as the PDF image I tried to load kept moving further and further down the device's screen until a user would need to scroll several screen fulls of blank screen to get to the document.

I see libraries such as android-pdf-viewer as a potential solution. But I'd prefer to link to another application rather than build in PDF support (including the fonts, etc) into my application. This then allows my application to support multiple PDF viewer applications - choosing one that the user has already installed or suggesting my favorite one if no compatible reader is present when I need it. Potentially I could see using these types of libraries to create such an application and load it to the market place, but before doing that I want to make sure that I'm not re-inventing the wheel.

I found the droid-reader application which looks promising, but this doesn't appear to be available from the market place. While I'm personally comfortable with the gymnastics of downloading files to my sdcard and installing from there, its not a viable option for the general public user that I'm targeting.

Community
  • 1
  • 1
Colin
  • 1,119
  • 12
  • 17
  • what is the mime type? try application/pdf – Darren Kopp Aug 05 '11 at 03:29
  • For local files I set the mime type to be application/pdf, but this still does not return any viable activity if one has not been previously installed that "registers" to be a handler for this type of file. ` webUrl = "file.pdf"; path = Uri.parse(webUrl); intent = new Intent(Intent.ACTION_VIEW); intent.setData(path); riList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); riList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); ` – Colin Aug 05 '11 at 16:49
  • Ran out of time editing the above comment... In both cases "riList" is empty, with our without the mime type set when the device does not have a default viewer installed. I'm looking for one to recommend. – Colin Aug 05 '11 at 16:58

1 Answers1

0

I hope the following code snippit would be helpful to you for reading pdfs. It will use the default pdf viewer that has been set on your device.

Intent intent= new Intent(Intent.ACTION_VIEW);
File f = new File("/mnt/sdcard/file.pdf");
intent.setDataAndType(Uri.fromFile(f),"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
getApplicationContext().startActivity(intent);
Amol Gupta
  • 704
  • 1
  • 8
  • 26
  • Sorry, I should have made it clearer in my question (it was too wordy)... I have used similar code (almost identical in fact) to invoke the default PDF viewer. The issue is that many devices do not have a default PDF viewer installed. What I am after is a pointer to a good/free PDF viewer that I can recommend to my users if they don't already have one installed. – Colin Aug 05 '11 at 16:36
  • Also `addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)`. See https://stackoverflow.com/a/59322760/2914140. – CoolMind Feb 01 '21 at 09:20