I need to show a notification in my android application.
I am using the following code:
NotificationCompat.Builder mBuilder= new NotificationCompat.Builder(baseContext).setLargeIcon(large_icon)
.setSmallIcon(R.drawable.message_received_small_icon)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setSound(soundUri);
.setContentTitle("New Message");
.setContentText("video");
This notification shows , Message Received icon on the left. To the right of the received message icon, it shows "DHan Nexus" as title and below it, it shows "Photo".
But instead of showing only "photo" string, i want to show camera icon + "photo" string . I have not found any way to show camera icon in the setContentText() API. Please help how to achieve this. Do i need to make a custom layout or any default approach will work .
Here is the image to make te question more clear:
i tried to use spannableString to show both icon and text . But it looks to be not working .
CharSequence cs = getContentIcon(text);
.setContentText(cs.toString());
private CharSequence getContentIcon(String text)
{
Drawable image = ContextCompat.getDrawable(baseContext, R.drawable.camera_icon);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
// Replace blank spaces with image icon
SpannableString sb = new SpannableString(" "+text);
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BASELINE);
sb.setSpan(imageSpan, 0, 20, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
return sb;
}