I use a snippet that looks almost identical to yours and it seems to
work fine.  The images I pull are from a Yahoo API, and they vary, but
they all seem to work.  When you say "this don't function" what do you
mean, is there an error in the log, a stacktrace?

This is the snippet I use (which again looks pretty much like what you
have, but works for me):

              try {
                    URL url = new
URL(report.getCondition().getImageLink());
                    URLConnection conn = url.openConnection();
                    conn.connect();
                    BufferedInputStream bis = new
BufferedInputStream(conn.getInputStream());
                    Bitmap bm = BitmapFactory.decodeStream(bis);
                    bis.close();
                    conditionImage.setImageBitmap(bm);
                } catch (IOException e) {
                    Log.e(Constants.LOGTAG, " " + CLASSTAG, e);
                }

conditionImage is just an ImageView.


On Apr 4, 9:55 am, "Andrea Bernardi" <[EMAIL PROTECTED]> wrote:
> Hello at all, i'm developing on Android since the last month and I've
> encountered this problem in these days.
>
> If I download an image from Internet with this code isn't correctly viewed:
>
> package org.ti.weather;
>
> import java.io.BufferedInputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.URL;
> import java.net.URLConnection;
>
> import android.app.Activity;
> import android.graphics.Bitmap;
> import android.graphics.BitmapFactory;
> import android.os.Bundle;
> import android.widget.ImageView;
>
> public class Weather extends Activity {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle icicle) {
>         super.onCreate(icicle);
>         setContentView(R.layout.main);
>         ImageView img = (ImageView) findViewById(R.id.weatherimg);
>
>         // this don't function
>         try {
>             URL aURL = new 
> URL("http://vdt.meteo.alice.it/meteo/imgs/icone/small/previsioni/notte/ser...
> ");
>             URLConnection conn = aURL.openConnection();
>             conn.connect();
>             InputStream is = conn.getInputStream();
>             BufferedInputStream bis = new BufferedInputStream(is);
>             Bitmap bm = BitmapFactory.decodeStream(bis);
>             bis.close();
>             is.close();
>             img.setImageBitmap(bm);
>         } catch (IOException e) {
>             // Reset to 'Dunno' on any error
>             showAlert("Error", 0, "Can't download image", "Ok", false);
>         }
>
>     }
>
> }
>
> where the main.xml is the following:
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
>     android:orientation="vertical"
>     android:layout_width="fill_parent"
>     android:layout_height="fill_parent"
>     >
> <ImageView
>     android:id="@+id/weatherimg"
>     android:layout_width="wrap_content"
>     android:layout_height="wrap_content"
>     />
> </LinearLayout>
>
> Instead, if I insert the same image in the directory res/drawable of the
> project and I use the following code the image is correctly viewed:
>
>     public void onCreate(Bundle icicle) {
>         super.onCreate(icicle);
>         setContentView(R.layout.main);
>         ImageView img = (ImageView) findViewById(R.id.weatherimg);
>
>         //this function
>         img.setImageDrawable(getResources().getDrawable(R.drawable.sereno));
>     }
>
> Have you some suggestion?
>
> Thanks
> Andrea
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to