Android wear - Notification - Image Span is not working

梦想的初衷 提交于 2019-12-24 00:23:13

问题


I am using ImageSpan in Android wear notification for styling in notification, but it's not working. Please tell me the procedure how to use ImageSpan in notifications any help is Appreciated. Following sample code i'm using.

SpannableStringBuilder title = new SpannableStringBuilder();

title.setSpan(new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE),title.length()+2,title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Thanks in advance.


回答1:


You can not use ImageSpan in Notification.


If you want to show images, there are two approaches to do it.
1. Custom Notification This is a code snip

      RemoteViews contentViews = new RemoteViews(context.getPackageName(), R.layout.view_notice_common);
        SimpleDateFormat fmt = new SimpleDateFormat("HH:mm");
        contentViews.setTextViewText(R.id.notice_time, fmt.format(Calendar.getInstance().getTime()));
        contentViews.setTextViewText(R.id.notice_title, title);
        contentViews.setTextViewText(R.id.notice_extend_message, content);
        Bitmap smallBitmap = bundle.getParcelable("APP_ICON");
        if (smallBitmap != null) {
            contentViews.setImageViewBitmap(R.id.notice_drawable, smallBitmap);
        } else {
            contentViews.setImageViewResource(R.id.notice_drawable, R.drawable.icon);
        }
        notification.contentView = contentViews;

2. Use Unicode Data
Code snip

  String originalStr = "emoji-" + newString(0x1f602) +newString(0x1f684)+"--over";
  public static final String newString(int codePoint) {
     return new String(Character.toChars(codePoint));
}

Then use originalStr as the Title Text.



来源:https://stackoverflow.com/questions/27958429/android-wear-notification-image-span-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!