epub 文件不可下载 [ANDROID]
我已将 set files 设置为 localhost 并设置 epub 文件的 href
链接..
<a href="more-utopia.epub" target="_blank"> more-utopia </a><br>
并且我尝试从自定义 Web 视图中浏览..但是当我单击下载链接时,它似乎没有下载..并使用自定义 Web 视图在浏览器中打开文件。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webview);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://10.0.2.2/epub");
web.setWebViewClient(new myWebView());
}
class myWebView extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url = "http://10.0.2.2/epub/";
view.loadUrl(url);
return true;
}
}
我想要做的是下载文件,并希望将下载位置的路径设置为用户选择的位置。
任何有用的提示都非常受欢迎。
I've set set files to localhost an set the href
links for the epub files ..
<a href="more-utopia.epub" target="_blank"> more-utopia </a><br>
and I've try to browse from my custom web view .. but when I click to download the link , it appears no download .. and open the file in the browser with custom web view.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webview);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://10.0.2.2/epub");
web.setWebViewClient(new myWebView());
}
class myWebView extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url = "http://10.0.2.2/epub/";
view.loadUrl(url);
return true;
}
}
What I want to do is to download the files and want to set path the download location to user selected location .
Any helpful tips are humbly welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码的设置是为了防止人们下载任何内容。每次他们单击链接时,您都会让他们再次加载原始网页。尝试在您的
WebView
上使用setDownloadListener()
。或者,更改您的shouldOverrideUrlLoading()
以执行您的问题所说的您希望它执行的操作。Your code is set up to prevent people from downloading anything. Every time they click the link, you have them load the original Web page again. Try using
setDownloadListener()
on yourWebView
instead. Or, change yourshouldOverrideUrlLoading()
to do what your question says you want it to do.