简体   繁体   中英

Android: How To Load Image From Url?

I need load an image from URL into Android Application.

Next I created a sample android project which would invoke a .NET web service

    while (reader.Read())
    {
        result.Append(reader["Pic"].ToString() + "<b><font size=600 face=sans-serif color=#243c45>"
            + Convert.ToDateTime(reader["PicDate"]).ToString("dd/MM/yyyy") + "</font></b><br />" 
            + reader["PicTitle"].ToString() + "<br /><a href=http://www.xxxxxxx.com/?ID=" 
            + reader["PicID"].ToString() + ">http://www.xxxxxxx.com/?ID=" + reader["PicID"].ToString() + "</a><br /><br /><br />");
    }

And I tried the output in smartphone.

All values ​​taken from the database via .NET web service are published correctly in android application and in smartphone only the value of

reader["Pic"].ToString()

show the link of the image and not the image:

https://lh6.googleusercontent.com/ ........

What shall I do?

Thanks,

EDIT

Thank you for help, I use in application:

 SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
 textView.setText(Html.fromHtml(response.toString()));
 textView.setMovementMethod(LinkMovementMethod.getInstance());

I tried this lib on this link https://github.com/koush/UrlImageViewHelper

try {
    httpTransport.call(SOAP_ACTION, envelope);

    SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
    UrlImageViewHelper.setUrlDrawable(imagepic, "http://www.myurl/images/logo.gif");

    textView.setText(Html.fromHtml(response.toString()));
    textView.setMovementMethod(LinkMovementMethod.getInstance());               

} catch (Exception exception) {
    textView.setText(exception.toString());
}

But I've this error:

java.lang.NullPointerException

There is a solution for you and it is URLImageViewHelper.

Try finding this lib on this link https://github.com/koush/UrlImageViewHelper

Basic Usage:

UrlImageViewHelper.setUrlDrawable(imageView, "http://example.com/image.png");

I believe that you will find everything you need there.

Hope this helps : )

You can try Universal Image Loader or Picasso. It have caching and threading solutions, many utilities and easy to use

I'm using Universal Image Loader. Source code of Library and Sample on github https://github.com/nostra13/Android-Universal-Image-Loader

Picasso Home page: http://square.github.io/picasso/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM