Howto download Image from URL in android

Code for download image:

File direct = new File(Environment.getExternalStorageDirectory()
        + "/LightBringer");

if (!direct.exists()) {
    direct.mkdirs();
}

DownloadManager mgr = (DownloadManager) getApplication().getSystemService(Context.DOWNLOAD_SERVICE);

Uri downloadUri = Uri.parse(uRl);
DownloadManager.Request request = new DownloadManager.Request(
        downloadUri);

request.setAllowedNetworkTypes(
        DownloadManager.Request.NETWORK_WIFI
                | DownloadManager.Request.NETWORK_MOBILE)
        .setAllowedOverRoaming(false).setTitle("Demo")
        .setDescription("Something useful. No, really.")
        .setDestinationInExternalPublicDir("/LightBringer", "fileName.jpg");

mgr.enqueue(request);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s