使用谷歌文档在 webview 中显示 pdf 文件(存储在谷歌驱动器中) [英] Display the pdf file(stored in google drive) in webview by using google docs
问题描述
我的 pdf 文件存储在某个网站例如:
应该怎么做才能使用我自己的 google 驱动器中的 pdf 在 webview 中打开
我已关注 CommonsWare、Stuart Siegler, Samir Mangroliya 但没有任何效果.:(
我有一个 WebView,我的 pdf 存储在 google drive 中的链接是:
String myPdfUrl = "https://drive.google.com/file/d/1fQfqgEmz-AiCpdHEIh7SNwdnAkQFqDQp/view";
不要忘记/view".
还有我用于显示的 java 代码:
private void displayWebView() {webView.getSettings().setJavaScriptEnabled(true);webView.setWebViewClient(new WebViewClient(){@覆盖public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {view.loadUrl(myPdfUrl);返回真;}});webView.loadUrl(myPdfUrl);}
并在 onCreate()
@SuppressLint("SetJavaScriptEnabled")
@SuppressLint("SetJavaScriptEnabled")@覆盖protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.act
My pdf file is stored in some website ex: http://www.pdf995.com/samples/pdf.pdf
Now I can't rely on other websites for my app. So
- I've downloaded the pdf doc
- uploaded in google drive
- Got my own link for pdf
- Trying to open that in
webview
using google docs - FAILED
Now the links are as follows
pdf stored in other website link: "http://www.pdf995.com/samples/pdf.pdf"
Sharable link of pdf saved in google drive: "https://drive.google.com/open?id=0B8e4zX5Y1S0XV0U0UTZJOUVma00"
If it's preceded with google docs : "https://docs.google.com/gview?embedded=true&url=https://drive.google.com/file/d/0B8e4zX5Y1S0XV0U0UTZJOUVma00/view"
Result,
Other websites may change their url at anytime. Can't rely on it.
If I use the google drive link alone, then it is opening in web browser not within the app.
If preceded with google docs, it is not resulting in a pdf doc. I get something like this.
What should be done so that I can use my own pdf from google drive to open in webview
I've followed CommonsWare, Stuart Siegler, Samir Mangroliya But nothing works. :(
I have a WebView, and the link to my pdf stored in google drive is:
String myPdfUrl = "https://drive.google.com/file/d/1fQfqgEmz-AiCpdHEIh7SNwdnAkQFqDQp/view";
Don't forget "/view".
And my java code for display:
private void displayWebView() {
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(myPdfUrl);
return true;
}
});
webView.loadUrl(myPdfUrl);
}
And add @SuppressLint("SetJavaScriptEnabled")
above onCreate()
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act
这篇关于使用谷歌文档在 webview 中显示 pdf 文件(存储在谷歌驱动器中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!