java – Uploading pictures from the web to the Android application


Interested in the question of such an implementation, for example: there is a picture on the html page, how can I load it into the application and show it in the ImageView? Newbie in programming, can you tell me the resources and whether?


A good example with inheriting the image loader from AsyncTask and defining its doInBackground () method, taken from the English SO , which took it from Android Developers, which has already removed it.

AsyncTask itself is an implementation of a short asynchronous request for the main GUI thread without having to poke around with the threads yourself.

// Показать картинку
new DownloadImageTask((ImageView) findViewById(

public void onClick(View v) {
    startActivity(new Intent(this, IndexActivity.class));


private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    public DownloadImageTask(ImageView bmImage) {
        this.bmImage = bmImage;

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new;
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Ошибка передачи изображения", e.getMessage());
        return mIcon11;

    protected void onPostExecute(Bitmap result) {

And in the manifest for the application, of course, you need to allow the download:

<uses-permission android:name="android.permission.INTERNET" />

If you need it quickly and without any asynchrony, error handling, etc.:

URL newurl = new URL(image_location_url); 
mIcon_val = BitmapFactory.decodeStream(newurl.openConnection() .getInputStream());

For the very lazy, the one-liner on Picasso is :

Scroll to Top