My Android Application has to be able to send short alerts out to a large group of people. The obvious place to do this is in the notification center. The full notification shows up in the ticker without a problem, but in the notification center a user can only see the first couple words and then an elipsis. The notifications are not long at all, just 10-15 words at the most. How can I make the text wrap down to a new line?
My code to build the notifications is here
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.splash)
.setContentTitle("Student Engauge")
.setContentText(extras.getString("message"))
.setAutoCancel(true)
.setTicker(extras.getString("message"));
final int notificationId = 1;
NotificationManager nm = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notificationId, mBuilder.build());
To show large chunk of text, use the BigTextStyle. Here is a sample code as given in BigTextStyle. This notification will one line of text and will expand to more lines if needed.
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();
For android support library
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(aVeryLongString))
.build();
For Android 4.1 and later devices, big view is the most suitable solution to show large amount of text. For pre 4.1 devices, you can use custom notification layout to show more data like mentioned here. But you should keep in mind two things:
From the official documentation
Caution: When you use a custom notification layout, take special care to ensure that your custom layout works with different device orientations and resolutions. While this advice applies to all View layouts, it's especially important for notifications because the space in the notification drawer is very restricted. Don't make your custom layout too complex, and be sure to test it in various configurations.
Custom notification layouts have some limitations. Too long texts are not shown fully, but 10-15 words probably fit to the custom layout. This answer has more info about the limitation of custom notification layouts
Related
I am implementing notifications and want to group them for display in notification bar.
Currently I am implementing the example from
Create a Group of Notifications in Android's official developer documentation.
I implemented this method:
private void makeNotification()
{
createNotificationChannel();
int SUMMARY_ID = 0;
String GROUP_KEY_WORK_EMAIL = "com.android.example.WORK_EMAIL";
String CHANNEL_ID = "MY_CHANNEL_ID";
Notification newMessageNotification1 =
new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_map_position_icon)
.setContentTitle("First summary")
.setContentText("You will not believe...")
.setGroup(GROUP_KEY_WORK_EMAIL)
.build();
Notification newMessageNotification2 =
new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_map_nav_position_icon_grey)
.setContentTitle("Second summary")
.setContentText("Please join us to celebrate the...")
.setGroup(GROUP_KEY_WORK_EMAIL)
.build();
Notification summaryNotification =
new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
.setContentTitle("Total summary")
.setContentText("Two new messages")
.setSmallIcon(R.drawable.ic_wdw_dont_drive)
.setGroup(GROUP_KEY_WORK_EMAIL)
.setGroupSummary(true)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(1, newMessageNotification1);
notificationManager.notify(2, newMessageNotification2);
notificationManager.notify(SUMMARY_ID, summaryNotification);
}
The method createNotificationChannel()just creates the channel, I left it out here for better readability.
Now the documentation says:
On Android 7.0 (API level 24) and higher, the system automatically builds a summary for your group using snippets of text from each notification.
So the last notify() call shall be optional and creating the summaryNotification, too. But this example only works for me when I notify the summary notification. When I don't do that, the notifications are not grouped.
What is going wrong here?
On Android 7.0 (API level 24) and higher, the system automatically builds a summary for your group using snippets of text from each notification.
"Summary [text]" but not "Group summary notification". This just means that whatever text you set in summary notification style it will be replaced by combined text from grouped notifications for Android >= N.
This doesn't affect the fact that the notifications are not grouped without summary.
Yes, this was highly misleading for me too, had to learn it the hard way. Try building the group on Kitkat and compare it to Nougat one.
Account details on Mixpanel:
maaz.shaikh#bwellthy.com
Notification text: Hey {{USER_NICK_NAME}}, you can check your HbA1c test result by clicking on it, then click GET STARTED to start your journey with us.
Notification custom packet: { "mp_icnm_l": "app_logo", "mp_icnm_w": "notification_logo", "mp_color": "#FF7531", "sound": "yes", "vibrate": "yes"}
The notification pops up on android device like this, but does not enlarge on dragging it downwards
I am using the latest release of Mixpanel(v5.2.1) in the Android code.
Mixpanel is using BigStyle Text notifications in their library, so ideally the single line notification on dragging should enlarge on dragging it.
Can you tell me the possible reason for this?
Use BigTextStyle for setting big text in notification.
Notification notification = new Notification.Builder(mContext)
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();
I am trying to show a notification from my Watch face, as I want to show additional information when the user first opens the watchface.
This is similar to the GMT watch face that is installed with the LG G Watch R, that asks the user to swipe left to select the timezone.
This code does not seem to work for me:
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle("Title")
.setContentText("Content");
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.notify(1, builder.build());
This was copied from one of Android wear's examples (was not used in a watchface example, just a regular wear app)
You are most likely missing the icon, you need to specify the icon for Android to show your notification. Try specifying everything that the example from the docs mentions:
Notification noti = new Notification.Builder(mContext)
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.build();
So I have set up a 2-page Android wear notification (dispatched from the device) as such:
final NotificationCompat.Builder mainNotificationBuilder = new NotificationCompat.Builder(this)
.setDefaults(android.app.Notification.DEFAULT_ALL)
.setSmallIcon(R.drawable.icon)
.setStyle(bigStyle)
.setContentIntent(contentIntent);
android.app.Notification secondNotification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setLargeIcon(balanceBackgroundImage)
.setStyle(bigStyle2)
.build();
android.app.Notification twoPageNotif = mainNotificationBuilder
.extend(new NotificationCompat.WearableExtender()
.setContentIcon(R.drawable.icon)
.setBackground(backgroundImage)
.addPage(secondNotification)
)
.setSmallIcon(R.drawable.icon)
.build();
However, the small icon only appears on the first page, but I want it to appear on both!
Is this even possible? I have a feeling that its not, and that the icon can only appear on the first page of a multi-page watch notification, but I wanted to get confirmation from you all.
Thanks in advance :\
Your thinking is correct: the small icon only appears on the first page of a notification.
I'm developing an application for android 2.3.3. I am showing a notification but the text of this notification is too long and its not showing the full text and its being cut so how can I show my full text in my notification?
Here's the code:
String message = "Tonights Taraweeh consists of Alif Lam Mim and the first quarter of Sayaqul. The Surahs covered are Al-Fatiha(The Opening),and the first two-thirds of Al-Baqara(The Cow).";
Notification notification = new Notification();
notification.setLatestEventInfo(context, title, message, contentIntent);
Expanded notifications are only available from Android 4.1, read here
Android 2.3.3 uses the old notifications without expansion. You must user a shorter text, cut your text (and show the full text when user click on it) or adapt the text if you are showing the notification in Android 4.1 or older.
I short you have to set the BigTextStyle
Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.new_mail)
.setContentTitle(emailObject.getSenderName())
.setContentText(emailObject.getSubject())
.setLargeIcon(emailObject.getSenderAvatar())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(__BigTextHere___))
.build();