How to open pdf from url online in Android without download option?

人盡茶涼 提交于 2020-05-17 06:33:25

问题


In my app I want the user to read the pdf files inside my app without any option to download them. How can I do this? I am using the following code but not working-

WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.loadUrl("https://docs.google.com/viewer?"+pdf_url);

Is there any other way to do this? If you can do it?


回答1:


You can open pdf from URL online in Android without a download option.

Kotlin

val path="https://github.github.com/training-kit/downloads/github-git-cheat-sheet.pdf"

activityWebViewBinding.webview.settings.loadWithOverviewMode = true
activityWebViewBinding.webview.settings.javaScriptEnabled = true
val url = "https://docs.google.com/gview?embedded=true&url=$path"
activityWebViewBinding.webview.loadUrl(url)

Java

 String path="https://github.github.com/training-kit/downloads/github-git-cheat-sheet.pdf";

 webview.settings.setLoadWithOverviewMode(true);
 webview.settings.setJavaScriptEnabled(true);
 String url = "https://docs.google.com/gview?embedded=true&url"+path;
 webview.loadUrl(url);


来源:https://stackoverflow.com/questions/61005179/how-to-open-pdf-from-url-online-in-android-without-download-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!