如何下载WebView中由URL创建的文件?

时间:2018-07-08 15:27:57

标签: java android webview download latex

在我的应用程序中,我让用户将乳胶文件的内容写在txt文件中。我也想将其转换为pdf文件。我使用以下代码:

String content; // The content for the pdf in latex scouce code
String title; // title for the pdf-file
String url = "https://latexonline.cc/compile?download="+title+".pdf&text="+ encodeURIComponent(content);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

(URL的示例可以是https://latexonline.cc/compile?download=example.pdf&text=%5Cdocumentclass%5B%5D%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AHello%20World%0A%5Cend%7Bdocument%7D。)

它将在浏览器中打开LaTeX.Online,该浏览器将创建我想要的pdf。效果很好,但是打开浏览器需要很多时间,所以我想在我的应用中打开网址:

 String url = "https://latexonline.cc/compile?download="+title+".pdf&text="+ encodeURIComponent(content);
 setContentView(R.layout.webpage);
 WebView webView = findViewById(R.id.webView);
 webView.getSettings().setJavaScriptEnabled(true);
 webView.setWebViewClient(new WebViewClient(){
     @Override
     public boolean shouldOverrideUrlLoading(WebView view, String url){
         view.loadUrl(url);
         return true;
     }
 });
 webView.loadUrl(url);

它可以很好地打开网页,但问题是它没有下载任何内容。

编辑:如果我使用download-manager,则会下载网页(正在LatexOnline正在编译...),而不下载Latex-online生成的pdf。

如果您知道如何解决此问题,或者有其他方法可以将乳胶文件转换为pdf,请在这里共享吗?

在此先感谢您的英语不好。

0 个答案:

没有答案