Android Question Intent for Drive PDF Viewer

Discussion in 'Android Questions' started by tdocs2, Apr 28, 2015.

  1. tdocs2

    tdocs2 Well-Known Member Licensed User

    Greetings.

    Thank you in advance for answering my question.

    How do I set up an intent to start the Drive PDF Viewer with a specific file?

    For example, the code below (courtesy of NJDude here) launches the Adobe Reader for a speciific pdf.

    Code:
    Dim i As Intent

    i.Initialize(i.ACTION_VIEW, 
    "file:///" & File.DirDefaultExternal & "/test.pdf")
    i.SetComponent(
    "com.adobe.reader/.AdobeReader")

    StartActivity(i)
    Sandy
     
  2. NJDude

    NJDude Expert Licensed User

    I don't think Google Drive opens the file but Google Docs, try this:
    Code:
    Private i As Intent

    i.Initialize(i.ACTION_VIEW, 
    "file:///" & File.DirDefaultExternal & "/myPDF.pdf")
    i.SetComponent(
    "com.google.android.apps.docs/com.google.android.apps.viewer.PdfViewerActivity")

    StartActivity(i)
     
  3. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, NJ.

    I am very appreciative of your contributions and generosity.

    Your solution works (but I did not expect anything else). As usual, you hit the mark.

    PROLOGUE

    I am a little confused (maybe a lot). First, I do not have Google Docs installed in the tablet in which I tested your solution (I have Sheets and Drive). To double verify, I went to Google Play and found the Google Docs app and is asking me to Install (if I had it installed, it would ask me to Open).

    Using the fantastic app, Phone Info by UncleDroid :),
    Drive (Google Drive)
    com.google.android.apps.docs
    Google Docs (I installed it AFTER I ran the code you provided) is
    com.google.android.apps.docs.editors.docs
    Google Sheets is
    com.google.android.apps.docs.editors.sheets
    There is an older? Google PDF Viewer:
    com.google.android.apps.PdfViewer which has a partial copyright by PDFium.

    The PDF Viewer app that comes from the intent you suggested is not the one from PDFium (although both apps are identical except the menu which shows About in the PDFium version).

    I could not find com.google.android.apps.docs.editors.PDFViewer?

    So, is this PDFViewer part of Google Drive? I had found this code in Stack Overflow (java continues to be coffee to me):

    Code:
    import android.support.v4.app.ShareCompat;

    Uri pdfUri = Uri.parse("file://sdcard/sdcard0/test.pdf");             
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                                         .setText(
    "Share PDF doc")
                                             .setType(
    "application/pdf")
                                             .setStream(pdfUri )
                                             .getIntent()
                                     .setPackage(
    "com.google.android.apps.docs");
    startActivity(shareIntent);

    Best regards.

    Sandy
     
    Last edited: Apr 28, 2015
  4. NJDude

    NJDude Expert Licensed User

    Yes, you are correct, com.google.android.apps.docs = Googledrive, I got confused for a second because of the package name. My apologies.
     
    tdocs2 and lemonisdead like this.
  5. tdocs2

    tdocs2 Well-Known Member Licensed User

    I was not quite correct, just confused.

    Thank you for the clarification.

    Best wishes.

    Sandy
     
  6. thehe

    thehe Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice