本文介绍了在WebView中打开Firebase存储pdf网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将Pdf文件上传到Firebase存储器,将pdf文件上传到Firebase存储器后,我得到了下载URL.现在,我想在我的android应用程序中的webview中打开pdf文件.
I have uploaded a Pdf file to firebase storage, after uploading the pdf file to firebase storage, I am getting the download url. Now I want to open the pdf file in webview in my android application.
下面是将pdf文件上传到Firebase存储后获取的网址.
Below is the url I am getting after uploading the pdf file to firebase storage.
以下是我在网络视图中打开pdf的方法
Below is my method for open pdf in webview
private void loadWebUrl(String url) {
myWebView.setBackgroundColor(Color.TRANSPARENT);
myWebView.getSettings().setJavaScriptEnabled(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setBuiltInZoomControls(true);
//url = "http://narsun.pk/profile.pdf";
if (url!=null&&!url.isEmpty()) {
myWebView.loadUrl("https://docs.google.com/viewerng/viewer?url="+url);
//myWebView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url="+url);
}else {
Utils.showToast(mActivity,"Sorry No Pdf url Exist!");
mActivity.onBackPressed();
}
}
请在错误的地方帮助我!谢谢
Please help me where I am wrong! Thanks
推荐答案
后期,但您应该对网址进行编码,
Late but you should encode your url,
try {
url=URLEncoder.encode(url,"UTF-8");
myWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+url);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
这篇关于在WebView中打开Firebase存储pdf网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!