-1

I want to open pdf file from url, so I used this code:

Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setDataAndType(Uri.parse(string), "application/pdf");
startActivity(browserIntent);

It's worked when the protocol is http, but not working if the protocol is https, I got error ActivityNotFoundException, any idea to fix this?

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Enda
  • 9
  • 1

1 Answers1

0

It's worked when the protocol is http, but not working if the protocol is https

Apparently, your device does not have a PDF viewer that supports downloading directly from https URLs.

any idea to fix this?

Download the PDF yourself (e.g., using OkHttp3 or HttpUrlConnection). Then, try opening a PDF viewer on the downloaded PDF (e.g., using FileProvider to serve it locally via a content Uri).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491