Android Question Intent for Drive PDF Viewer

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.

B4X:
Dim i As Intent

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

StartActivity(i)
Sandy
 

NJDude

Expert
Licensed User
I don't think Google Drive opens the file but Google Docs, try this:
B4X:
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)
 

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):

B4X:
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:

thehe

Member
Licensed User
Top