Reputation: 542
How to add small image(icon) at end of notification(Local notification) body. I am using NotificationCompat.Builder to create notification.I want to add small icon at the end of notification body.
Upvotes: 1
Views: 651
Reputation: 6583
You can use NotificationCompat.Builder#setCustomContentView(RemoteViews). In this related question you can see an example.
Take into account that the notification template has changed in Android N if you go that route, and usually the users expect a consistent UI. See Android N: Introducing upgraded Notifications
Upvotes: 0
Reputation: 21043
I think you can use spannable
String because setContentText(CharSequence message)
accepts 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);
And add it to message in notification builder.
NotificationCompat.Builder notification
= new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.app_icon)
.setStyle(new NotificationCompat.BigTextStyle().bigText(ssb))
.setContentTitle("Hello")
.setContentText(ssb);
I haven't tested it. But i think it should work. Watch out for index.
Upvotes: 2