4

I saw a way of reading online pdf files using google docs ...

Android - Load PDF / PDF Viewer

Is there a way we can use it to view local files stored in sd card

Community
  • 1
  • 1
xydev
  • 3,409
  • 5
  • 34
  • 54
  • it's long waited response..but can try this. http://androidyoungashram.blogspot.in/2011/02/read-pdf-in-android-without-third-party.html – CoDe Sep 14 '13 at 08:24

1 Answers1

0

You can launch an intent that will allow the user to choose what app will open the PDF with the following code, which will work for any file and mimetype. If the user doesn't have an app that can open it, you can display an error or do whatever else you need to do.

Note that the file must be world-readable, so it must be marked as such if it is on Internal storage, or it must be in external storage.

private void openFile(File f, String mimeType)
{
    Intent viewIntent = new Intent();
    viewIntent.setAction(Intent.ACTION_VIEW);
    viewIntent.setDataAndType(Uri.fromFile(file), mimeType);
    // using the packagemanager to query is faster than trying startActivity
    // and catching the activity not found exception, which causes a stack unwind.
    List<ResolveInfo> resolved = getPackageManager().queryIntentActivities(viewIntent, 0);
    if(resolved != null && resolved.size() > 0)
    {
        startActivity(viewIntent);
    }
    else
    {
        // notify the user they can't open it.
    }
}
jakebasile
  • 8,084
  • 3
  • 28
  • 34
  • To do that, you'd have to either write your own PDF parser, or use some sort of third party library. This is the "Android way" of using other apps to provide functionality: to a user, the reader that opens the PDF or other file will feel like part of your app. – jakebasile Feb 25 '11 at 05:27
  • webview does not render pdf as in iphone.. i may adopt one from net that show only one page at a time.. – xydev Feb 25 '11 at 05:31
  • No, the Android WebView doesn't display PDFs, third party apps are there to do that. You should try out the way I posted and see how it works, in the end it will give a better, more consistent user experience than doing something non-standard on Android. – jakebasile Feb 25 '11 at 05:34
  • 1
    mm... always the requiremnts su*** .. this link may help http://ecestage.googlecode.com/svn-history/r12/branches/src/com/pdfviewer/PdfViewerActivity.java – xydev Feb 25 '11 at 06:03