1
I have an android app, and wanted to know how to open a PDF file that will be on Firebase in my application. I do not need him to download the file, simply an Intent where I pass the file path (in case the link) and when clicking the button the default android application open and render the file. What I have currently done is a webview that opens the pdf link by google Docs, however is not working anymore And that’s why I wanted the PDF to be opened through the standard cell phone reader. Below the Java code of the button that calls the webview:
public void onClick(View v) {
//Intent intent = new Intent(PdfList.this, WebViewPDF.class);
//startActivity(intent);
String pdf = "AQUI ENTRA O LINK DO PDF NO FIREBASE";
WebViewPDF.OpenPDF.setPdf(pdf);
Intent intent = new Intent(PdfList.this, WebViewPDF.class);
startActivity(intent);
}
And below the webview code that opens the PDF on the screen within the application
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String pdf = OpenPDF.getPdf();
WebView mWebView = new WebView(WebViewPDF.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + pdf);
setContentView(mWebView);
}
public abstract static class OpenPDF extends WebViewPDF{
private static String pdf;
public static void setPdf(String pdfLink){
pdf = pdfLink;
}
public static String getPdf(){
return pdf;
}
}
But that depends if the device has installed some PDF reader; If by chance you don’t have it, then it won’t work. But you can make a Webview call to view it. What have you already done?! You can insert it into the question?!
– viana
@acklay updated the question with the current webview code using.
– Túlio Marcos
I believe that there is no standard reader on Android. Generally if you do not have any app that reads pdf, the file will not be recognized. Look at that answer, in the second option. https://answall.com/a/218776/35406 It will probably help you.
– viana