0

I'm developing an Android App. Webservice returns me a String like this :

String response = getStringFromWebsevice();

response = "This is my first picture < img align=\"Middle\" alt=\"\" border=\"0\" class=\"oImage\" height=\"750\" src=\"http://abc.com/2013/05/20/pic1.jpg\" width=\"500\"/>.This is second picture < img align=\"Middle\" alt=\"\" border=\"0\" class=\"oImage\" height=\"750\" src=\"http://abc.com/2013/05/20/pic2.jpg\" width=\"500\"/>";

How can i get image url inside String returned from Webservice ?

green.android
  • 711
  • 3
  • 7
  • 21

1 Answers1

0

You can use Asynchronous Image loader to load images asynchronously. Check the below code.

  private class FetchImageTask extends AsyncTask<String, Integer, Bitmap> {
  @Override
    protected Bitmap doInBackground(String... arg0) {
    Bitmap b = null;
    try {
        b = BitmapFactory.decodeStream((InputStream) new URL(arg0[0]).getContent());
    }
    catch (MalformedURLException e) {
        e.printStackTrace();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    return b;
    }
  }

To implement use this code.

   new FetchImageTask() {
    @Override
    protected void onPostExecute(Bitmap result) {
        if (result != null) {
            image.setImageBitmap(result);
        }
    }
}.execute("IMAGE_URL");
Make it Simple
  • 2,299
  • 4
  • 32
  • 57