Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android multiline notifications / notifications with longer text

Tags:

I need to create a Notification with a longer text, is that possible? By default it is not, but you can use a custom layout, which is what I did. Now I can display multiple lines, but as you can see, the text is still broken / not displayed completely? ): Can someone please tell me what I am doing wrong / if there's a fixed limit for the size of notifications? If you look at the screenshot you will notice, that there is still a lot of space left... Thanks for any hint!

BTW here's the XML used for the custom layout, based on http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"           android:orientation="horizontal"           android:layout_width="fill_parent"           android:layout_height="fill_parent"           android:padding="3dp"           > <ImageView android:id="@+id/image"           android:layout_width="wrap_content"           android:layout_height="fill_parent"           android:layout_marginRight="10dp"           /> <TextView android:id="@+id/text"           android:layout_width="wrap_content"           android:layout_height="fill_parent"           android:textColor="#000"           /> </LinearLayout> 

Longer notification text

like image 574
stefan.at.wpf Avatar asked Jun 15 '11 12:06

stefan.at.wpf


People also ask

How can Android handle multiple push notifications?

If you have multiple push providers you will need create your own Messaging Service to handle push notifications. You will need to pass new tokens to Swrve and make sure Swrve is set to handle incoming notifications.

How do you handle multiple notifications?

Set the unique id to let Notification Manager knows this is a another notification instead of same notification. If you use the same unique Id for each notification, the Notification Manager will assume that is same notification and would replace the previous notification.


2 Answers

NotificationCompat.Builder mBuilder =             new NotificationCompat.Builder(this)                     .setSmallIcon(R.drawable.ic_notification)                     .setContentTitle(title)                     .setStyle(new NotificationCompat.BigTextStyle()                                       .bigText(message))                     .setContentText(message)                                                                 .setDefaults(NotificationCompat.DEFAULT_SOUND)                     .setContentIntent(contentIntent)                     .setAutoCancel(true);  mNotificationManager.notify(requestID, mBuilder.build()); 

once reffer https://developer.android.com/guide/topics/ui/notifiers/notifications.html

like image 147
sreeniwasa Avatar answered Dec 03 '22 11:12

sreeniwasa


For Jelly Bean and higher you can use an expandable notification. The easiest way is to use the NotificationCompat.BigTextStyle for your notification.

Like so:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(getString(R.string.title)); bigTextStyle.bigText(getString(R.string.long_explanation));  mBuilder.setStyle(bigTextStyle); 
like image 45
Ciske Avatar answered Dec 03 '22 11:12

Ciske