I am creating an app where people can share documents with it. I want to create it in a way that when a user clicks on the document, it opens inside the application, rather than downloading and opening it with a third party app like WPS. I want the document to open using a PDFView inside An alertDialog. This code that Am using only creates an alertDialog, but it does not load the PDF. Any ideas on how the PDF can be loaded? It is doable?
holder.postDocument.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.AlertDialog);
builder.setTitle("Post document");
final String pdfUrl = "https://www.tutorialspoint.com/computer_programming/computer_programming_tutorial.pdf";
final PDFView pdfView = new PDFView(mContext, null);
pdfView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
pdfView.fromUri(Uri.parse(post.getPostdocument() pdfUrl)).load();
builder.setView(pdfView);
builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.show();
}
});
1 - First you need to download the PDF file and store it into your phone storage :
2 - When the download process finished, show the PDF in custom dialog as follows :
3 - Dialog XML :
4 - Call the Download class like this :
Result :
The used libraries :
Permissions :