I am creating a chat application and I am trying to add an image to EditText using Picasso to get the image from the URL, as well as append and ImageGetter to attach the image to EditText. However, what I performed below does not work, because when adding messages when using the application, nothing is displayed (but the message appears in the database).
I tested without using Picasso, since just using ImageGetter with the image resource in the application works just fine, only this is not from the URL that is required.
What is the correct way to configure the ImageGetter method and / or add to make this function work with Picasso? Or is there an easier way?
Adding Method:
public void appendToMessageHistory(final String username, final String message) { if (username != null && message != null) { Picasso.with(getBaseContext()) .load("http://localhost:3000/uploads/campaign/image/2/2.jpg") .into(new Target() { @Override public void onPrepareLoad(Drawable arg0) { } @Override public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) { Drawable drawImage = new BitmapDrawable( getBaseContext().getResources(), bitmap); drawImage.setBounds(0, 0, drawImage.getIntrinsicHeight(), drawImage.getIntrinsicWidth()); messageHistoryText.append(Html.fromHtml("<b>" + username + ":" + "</b>" + "<br>")); messageHistoryText.append(Html.fromHtml(message + "<hr>" + "<br>") + System.getProperty("line.separator") + ""); messageHistoryText.append(Html .fromHtml("<img src = '" + drawImage + "'/>", imageGetter, null)); } @Override public void onBitmapFailed(Drawable arg0) { } }); } }
ImageGetter:
ImageGetter imageGetter = new ImageGetter() { Drawable imageUsed=null; @Override public Drawable getDrawable(String source) { Picasso.with(getBaseContext()) .load("http://localhost:3000/uploads/campaign/image/2/2.jpg") .into(new Target() { @Override public void onPrepareLoad(Drawable arg0) { } @Override public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) { Drawable drawImage = new BitmapDrawable( getBaseContext().getResources(), bitmap); drawImage.setBounds(0, 0, drawImage.getIntrinsicHeight(), drawImage.getIntrinsicWidth()); imageUsed=drawImage; } @Override public void onBitmapFailed(Drawable arg0) { } }); return imageUsed; } };
source share