Android 在本地通知的正文文本末尾添加图标

Android 在本地通知的正文文本末尾添加图标,android,android-notifications,android-bitmap,Android,Android Notifications,Android Bitmap,如何在通知(本地通知)正文末尾添加小图像(图标)。 我正在使用NotificationCompat.Builder创建通知。我想在通知正文的末尾添加一个小图标。我想您可以使用spannable字符串,因为setContentText(CharSequence消息)接受CharSequence String msg="Hello world"; SpannableStringBuilder ssb = new SpannableStringBuilder(msg); ssb.s

如何在通知(本地通知)正文末尾添加小图像(图标)。
我正在使用NotificationCompat.Builder创建通知。我想在通知正文的末尾添加一个小图标。

我想您可以使用
spannable
字符串,因为
setContentText(CharSequence消息)
接受
CharSequence

  String msg="Hello world";
    SpannableStringBuilder ssb = new SpannableStringBuilder(msg);
    ssb.setSpan(new ImageSpan(this, R.drawable.app_icon), msg.length()-1, msg.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
并将其添加到通知生成器中的消息中

 NotificationCompat.Builder  notification
                = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.app_icon)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(ssb))
                .setContentTitle("Hello")
                .setContentText(ssb);
我还没有测试过。但我认为它应该起作用。注意索引。

您可以使用。在这里你可以看到一个例子


考虑到Android N中的通知模板已经发生了变化,如果你这样做的话,用户通常希望有一个一致的UI。请参见

您的代码“将图像添加到字符串”,如果我将字符串设置为textview,则效果良好,但在通知中,我没有收到图像。是的,正如我所说,我还没有测试它。奇怪的是,我认为它应该与
CharSequence
一起使用。请澄清。你应该继续前进。谢谢