I am trying to dynamically display images on a home screen widget. Since RemoveViews offer a very limited set of methods for interacting with the layout, I'm trying to use HTML to get the same effect. Regular HTML displays are ok ( <u>,<b>etc.), however I cannot display images. Instead, I get a small empty square in the TextView.
eg.
s = "<b>Hello</b> <img src='world'/>";
ImageGetter imgGetter = new ImageGetter(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.textarea, Html.fromHtml(s, imgGetter, null));
The getter image is as follows:
public class ImageGetter implements Html.ImageGetter
{
Context c;
public ImageGetter(Context c)
{
this.c = c;
}
public Drawable getDrawable(String source) {
Drawable d = null;
int resID = c.getResources().getIdentifier(source, "drawable", c.getPackageName());
d = c.getApplicationContext().getResources().getDrawable(resID);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
}
The code works fine if I use the usual action. I suspect this is an error / undocumented android function when used with AppWidgetProvider. I just need confirmation.