简体   繁体   中英

Android wear - Notification - Image Span is not working

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.

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.
在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM