Reputation: 1467
I have an html file with images and text on server. I want to download that HTML file along with images. I have code for downloading the html file. But how can i download the images along with the HTML file?
public void myDownload(String myURL, String title, String year, String branch, String section) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(myURL));
request.setTitle("File Download");
request.setDescription("Downloading....");
//request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.allowScanningByMediaScanner();
//request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
String nameOfFile = URLUtil.guessFileName(myURL, null, MimeTypeMap.getFileExtensionFromUrl(myURL));
//request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().getPath() + "/KiiTTimeTableData/" + year + "/" + branch + "/" + section + "/", nameOfFile);
request.setDestinationInExternalPublicDir("/KiiTTimeTableData/" + year + "/" + branch + "/" + section + "/", nameOfFile);
DownloadManager manager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
Upvotes: 0
Views: 1920
Reputation: 908
You can use JSoup to load the html into a Document element, then fetch all the img nodes and retrieve the image from the src attribute.
Consider the code example here: https://examples.javacodegeeks.com/enterprise-java/html/download-images-from-a-website-using-jsoup/
Upvotes: 1