Android Wear-通知-图片跨度不起作用

rgu*_*rgu 3 notifications android android-notifications wear-os

我在Android Wear通知中使用ImageSpan进行通知中的样式设置,但无法正常工作。如果有任何帮助,请告诉我该程序如何在通知中使用ImageSpan。以下示例代码我正在使用。

SpannableStringBuilder title =新的SpannableStringBuilder();

title.setSpan(新ImageSpan(上下文,bmp,ImageSpan.ALIGN_BASELINE),title.length()+ 2,title.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

提前致谢。

RxR*_*ead 5

您不能在Notification中使用ImageSpan。


如果要显示图像,可以采用两种方法。
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;
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

2.使用Unicode数据
代码片段

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

然后使用originalStr作为标题文本。
在此处输入图片说明