Created
September 26, 2019 09:04
-
-
Save PasanBhanu/46f08845ee3b7acf93de81acf8048fa2 to your computer and use it in GitHub Desktop.
Download Image from URL and Added to Gallery - Android (Java)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This method can be used to download an image from the internet using a url in Android. This use Android Download Manager to | |
download the file and added it to the Gallery. Downloaded image will be saved to "Pictures" | |
Folder in your internal storage | |
*/ | |
private void downloadImageNew(String filename, String downloadUrlOfImage){ | |
try{ | |
DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); | |
Uri downloadUri = Uri.parse(downloadUrlOfImage); | |
DownloadManager.Request request = new DownloadManager.Request(downloadUri); | |
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE) | |
.setAllowedOverRoaming(false) | |
.setTitle(filename) | |
.setMimeType("image/jpeg") // Your file type. You can use this code to download other file types also. | |
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) | |
.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,File.separator + filename + ".jpg"); | |
dm.enqueue(request); | |
Toast.makeText(this, "Image download started.", Toast.LENGTH_SHORT).show(); | |
}catch (Exception e){ | |
Toast.makeText(this, "Image download failed.", Toast.LENGTH_SHORT).show(); | |
} | |
} |
THANK YOU !
great work bro thanks
Amazing, Thanks u!
Does the downloaded image show in phone gallery?
@mahmood199 yes it is showing
super working this code thank you so mach
nice !!!
great thanks
thanks a lot
Works on android 11
This worked thank you
Bro this is the easiest way Thanks Bro
2 feb 2022 Android 11 working
Very good!! Thank you for sharing!
one of the easiest way I have ever seen .💫💫
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, it work