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

标签 android notifications android-notifications wear-os

我在 Android 穿戴通知中使用 ImageSpan 来设置通知样式,但它不起作用。请告诉我如何在通知中使用 ImageSpan 的过程,感谢任何帮助。按照我正在使用的示例代码。

SpannableStringBuilder title = new SpannableStringBuilder();

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

提前致谢。

最佳答案

您不能在 Notification 中使用 ImageSpan。


如果你想显示图片,有两种方法可以做到。
<强>1。自定义通知 这是一个代码 fragment

      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;

enter image description here

<强>2。使用 Unicode 数据
代码 fragment

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

然后使用originalStr作为Title Text。
enter image description here

关于Android wear - 通知 - 图像跨度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27958429/

相关文章:

java - 保存视频录制时本地通知不起作用

android - 在 aChartEngine 中平移时条与 Y 轴重叠

java - Android Studio 2.2.2 InvalidPathException

android - 尝试将序列化对象从 Android App 传输到 Servlet 时收到 NoSuchMethodException

java - Android 小通知图标在 5.1 中不显示(LOLLIPOP)

android - 如何使用服务每小时显示本地通知

android 通知大图像不工作

android - Eclipse需要经常重启logcat才能正常工作

ios - Swift:ViewDidLoad 在接受通知权限请求后不会继续

java - 如何使用 sse android 发布通知