0

Is there a way to open a pdf (stored on drive) to open in Google Drive PDF Viewer in Android. While I am using ACTION_VIEW, it shows open with options like drive and browser. Is there a way that by default it opens in Drive. It's okay even if it switches to drive by default.

My Code:

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pdf_link));
startActivity(myIntent);
Vichitr Gandas
  • 23
  • 1
  • 1
  • 6
  • You can target the intent directly https://stackoverflow.com/a/16986759/529282 Note that it's from seven years ago, the code might need some adjustment. Feel free to answer your own question if you managed to update it for current Android – Martheen Apr 26 '20 at 19:11
  • The user might not have that PDF viewer. And, the user might want to use a different PDF viewer. – CommonsWare Apr 26 '20 at 19:22
  • @CommonsWare it's okay. My target users are supposed to have Drive. And I can handle if drive doesn't exist with a check condition, and in that case, opening it in the way I am doing right now. – Vichitr Gandas Apr 27 '20 at 06:24

1 Answers1

0

I got an answer. Following code does select Google Drive by default.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(pdf_url));
intent.setPackage("com.google.android.apps.docs");
startActivity(intent);

But this still lists all google accounts and asks one to open with. How can we proceed with default google account to open the pdf in drive?

Vichitr Gandas
  • 23
  • 1
  • 1
  • 6