InputStream inputStream = null;
// TODO: Retrieve PDF from URL
private void retrievePDFFromURL(String urlString){
ExecutorService executorService = Executors.newSingleThreadExecutor();
Handler handler = new Handler(Looper.getMainLooper());
executorService.execute(() -> {
// we are using inputstream
// for getting out PDF.
try {
URL url = new URL(urlString);
// below is the step where we are
// creating our connection.
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
if (urlConnection.getResponseCode() == 200) {
// response is success.
// we are getting input stream from url
// and storing it in our variable.
inputStream = new BufferedInputStream(urlConnection.getInputStream());
}
} catch (IOException e) {
// this is the method
// to handle errors.
e.printStackTrace();
}
handler.post(() -> {
pdfView.fromStream(inputStream).load();
});
});
}
Try this code: