I am making an Android App which has a feature that allows users to upload and view PDF files. And for the app, Firebase is the backbone. At the current stage of the app, the PDF files get uploaded to Firebase Storage. But I am having a hard time viewing it. I get the download URL from Firebase and use it in the method: webView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + downloadURL) But the WebView shows me a grey background with "No Preview Available" written in the centre. I've opened the download URL on my browser and it displays the file perfectly (indicating that the file exists). How can i fix this issue?
Asked
Modified 6 years, 11 months ago
Viewed 2k times
Part of Mobile Development and Google Cloud Collectives
1 Answer
just write one line above
pdf_url=getArguments().getString("pdf_url"); //Ur Firebase Url progressBar=view.findViewById(R.id.course_content_progress); webView=view.findViewById(R.id.pdfviewr); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); } }); String url=""; try { url=URLEncoder.encode(pdf_url,"UTF-8"); //Url Convert to UTF-8 It important. } catch (UnsupportedEncodingException e) { e.printStackTrace(); } webView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url="+url); it's work for me.
Happy Coding
2 Comments
Edwin
Can you elaborate on the answer? Why did it work for you? :-) This helps users understand your answer.
Kalpesh A. Nikam
I understand What you want. So I did Something Just Checked.
downloadURL