我已经将一个 Pdf 文件上传到 firebase 存储,将 pdf 文件上传到 firebase 存储后,我得到了下载 url。现在我想在我的 android 应用程序的 webview 中打开 pdf 文件。
下面是我将 pdf 文件上传到 firebase 存储后得到的 url。
下面是我在webview中打开pdf的方法
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();
}
}
请帮我看看哪里错了!谢谢
最佳答案
晚了,但你应该对你的 url 进行编码,
try {
url=URLEncoder.encode(url,"UTF-8");
myWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+url);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
关于java - 在 webview 中打开 Firebase 存储 pdf url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47810673/