简体   繁体   English

Android服装 - 通知 - 图像跨度不起作用

[英]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. 我在Android服装通知中使用ImageSpan进行通知样式,但它不起作用。 Please tell me the procedure how to use ImageSpan in notifications any help is Appreciated. 请告诉我如何在通知中使用ImageSpan的任何帮助是赞赏的程序。 Following sample code i'm using. 以下是我正在使用的示例代码。

SpannableStringBuilder title = new SpannableStringBuilder(); SpannableStringBuilder title = new SpannableStringBuilder();

title.setSpan(new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE),title.length()+2,title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 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. 您无法在通知中使用ImageSpan。


If you want to show images, there are two approaches to do it. 如果要显示图像,有两种方法可以实现。
1. Custom Notification This is a code snip 1.自定义通知这是一个代码片段

      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 2.使用Unicode数据
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. 然后使用originalStr作为标题文本。
在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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