kabuto178
kabuto178

Reputation: 3167

getting image from remote server issue

Just two things, is this a good simple way to grab images? also when i do try it on the android AVD nothing gets displayed on screen as well as in log_cat, no errors or crashes. Here is my code:

public class MainActivity extends Activity {
Bitmap bitmap = null;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try{
        bitmap = getBitmap("https://twimg0-a.akamaihd.net/profile_images/2275552571/image_normal.jpg");
        ImageView img = (ImageView) findViewById(R.id.img);
        img.setImageBitmap(bitmap);
    }catch(Exception e){

    }

}

public Bitmap getBitmap(String bitmapUrl) { 

              try {

                URL url = new URL(bitmapUrl);

                return BitmapFactory.decodeStream(url.openConnection().getInputStream());

              }catch(Exception ex) {return null;}

            }


 }

Upvotes: 0

Views: 608

Answers (2)

Zellius
Zellius

Reputation: 256

It doesn't work because your picture's url starts with HTTPS. Try to use HttpGet. Something like that.

Upvotes: 0

Frank
Frank

Reputation: 790

try : http://code.google.com/p/android-imagedownloader/ .

You can download remote images synchronously, Asynchronously, etc. it works really good

    ImageDownloader imageDownloader = new ImageDownloader();
    imageDownloader.setMode(ImageDownloader.Mode.CORRECT);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.picture);

    imageView.setLayoutParams(new GridView.LayoutParams(140, 140));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setPadding(4, 4, 4, 4);

    List<ImageSize> images = this.pictures.get(position).getImages();

    imageDownloader.download(images.get(images.size()-3).getSource(), imageView);

Upvotes: 1

Related Questions