Html.fromHtmlを使用してBase64でimgを表示しようとしています
1つの画像のBase64文字列のタグがあります。
それが私のコードです:
public class GlossaryAdapter extends BaseAdapter{
...
private Resources res;
public GlossaryAdapter(Context context, ...) {
this.res = context.getResources();
...
}
public View getView(int position, View convertView, ViewGroup arg2) {
...
holder.tvContent.setText(Html.fromHtml(glossary.getContent(), new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
try {
byte[] data;
data = Base64.decode(source,Base64.DECODE);
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
return new BitmapDrawable(res, bitmap);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}, null));
Grossary.getContent()に含まれるもの:
<img src="AAAY5671NF..." />
この文字列をhtmlページでテストして動作しました。画像を表示します。
私はAndroid1.6を使用しています。そしてこのBase64クラス:http ://androidcodemonkey.blogspot.com/2010/03/how-to-base64-encode-decode-android.html
エラーは発生しませんでした。しかし、何も表示されていません。戻り値を「null」に変更すると、小さな灰色の四角が表示されます。
何か案は?