如何在没有下载选项的情况下在Android中从url在线打开pdf?

如何在没有下载选项的情况下在Android中从url在线打开pdf?

问题描述:

在我的应用程序中,我希望用户阅读我的应用程序中的pdf文件,而没有下载它们的任何选择.我怎样才能做到这一点?我正在使用以下代码,但无法正常工作-

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?

您可以在没有下载选项的情况下在Android中从URL在线打开pdf.

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

科特林

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);