A J
A J

Reputation: 4632

notification body multiline

enter image description here

how to make this in two line like

ALERT

Pending follow-ups: 9

Enquery not attended once: 11

I am passing a string value "Pending follow-ups: " + all_follow_ups + "\n" + "Enquery not attended once: " + noOfEnquiry but not showing in two line.

I am using it android:minSdkVersion="7"

Upvotes: 3

Views: 13998

Answers (2)

satorikomeiji
satorikomeiji

Reputation: 469

You could use RemoteViews for that.

In your custom_notification.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_notification"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

    <ImageView
        android:id="@+id/notifiation_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     />

    <TextView 
         android:id="@+id/notification_title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_toRightOf="@id/notification_image"
         android:layout_alignTop="@+id/notification_image"
     />

    <TextView
        android:id="@+id/notification_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/notification_image"
        android:layout_below="@+id/notification_title"
    />
    <TextView
        android:id="@+id/notification_text_second_line"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/notification_image"
        android:layout_below="@+id/notification_text"
    />

</RelativeLayout>

In notification building code:

RemoteViews contentView = new RemoteViews(getPackageName(),    R.layout.custom_notification);
contentView.setImageViewResource(R.id.notification_image,      R.drawable.notification_image);
contentView.setTextViewText(R.id.notification_title, "My custom    notification title");
contentView.setTextViewText(R.id.notification_text, "My custom notification text");
contentView.setTextViewText(R.id.notification_text_second_line, "My custom notification text second line");
NotificationCompat.Builder builder = new NotificationCompat.Builder(
            context);
Notification notification = builder
            .setAutoCancel(true)
            .setContent(contentView).build();
notificationManager.notify(0, notification);

Upvotes: 1

Siddharth_Vyas
Siddharth_Vyas

Reputation: 10100

Add this in your code :

NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
        Notification notification = builder.setContentIntent(contentIntent)
                .setSmallIcon(icon).setTicker(appname).setWhen(0)
                .setAutoCancel(true).setContentTitle(appname)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentText(message).build();

        notificationManager.notify(0, notification);

Also Check this : Notification expand

Hope this helps.

Upvotes: 4

Related Questions