安卓下载管理器从HTML获取链接并开始下载


Android Download Manager get link from HTML and start downloading

有没有办法要求Android下载管理器获取链接并立即开始下载。

示例网页

<html>
<head>
<title>Thank You</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<a href="http://domain.com/file.dat" title="Order" download>Download File</a>   
</body>
</html>

我正在使用的当前安卓下载管理器

                        public void onResponse(String response) {
                            // Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show();
                             downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
                             Uri Download_Uri = Uri.parse(url); // put here your URL that you get 
                             DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
                             request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
                             //Set whether this download may proceed over a roaming connection.
                             request.setAllowedOverRoaming(false);
                             //Set the title of this download, to be displayed in notifications (if enabled).
                             String link = url.toString();
                             String fileName = link.substring(link.lastIndexOf('/') + 1);
                             request.setTitle(fileName);
                             //Set a description of this download, to be displayed in notifications (if enabled)
                             request.setDescription("Android Data download using DownloadManager.");
                             //Set the local destination for the downloaded file to a path within the application's external files directory
                             //request.setDestnInExtFilesDir(this, Environment.DIRECTORY_DOWNLOADS,"");
                             downloadReference = downloadManager.enqueue(request);
                             Intent intent = new Intent();
                             intent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
                             startActivity(intent);
                         }

如果可能的话,请协助我修改代码,对不起,我是新手。

非常感谢!

使用 JSOUP,您可以使用它来获取属性、文本、

Document doc = Jsoup.connect("http://example.com")// html page link
Element link = doc.select("a").first();
String text = doc.body().text(); // "An example link"
String linkHref = link.attr("href"); // "http://example.com/"
String linkText = link.text(); // "example"

要在 gradle 中添加的依赖项,

compile 'org.jsoup:jsoup:1.7.3'

例如,http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/