问题
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