firstly, I read this and use this simple code to multiple notification:
public static void notifyMessage()
{
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int notifyID = 1;
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
int numMessages = 0;
builder.setSmallIcon(R.drawable.icon)
.setContentTitle("Event tracker")
.setContentText("Events received")
.setNumber(++numMessages)
.setWhen(System.currentTimeMillis()).setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig"));
Notification notification = builder.build();
notificationManager.notify(1, notification);
It's working. if message's length is bigger than usual limit , it will show "bigbig...".
in next step, I want use user's message to show in notification. so I've changed function to :
public static void notifyMessage(String message , boolean flashLed)
{
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int notifyID = 1;
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
int numMessages = 0;
builder.setSmallIcon(R.drawable.icon)
.setContentTitle("Event tracker")
.setContentText(message)
.setNumber(++numMessages)
.setWhen(System.currentTimeMillis()).setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message));
if (flashLed)
{
builder.setLights(0xFFFF0000, 500, 500);
}
Notification notification = builder.build();
notificationManager.notify(1, notification);
}
I trying to show message instead of "bigbigbig...." but always it show me short type of notification. I've also tried this:
public static void notifyMessage(String message)
{
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
String[] events = new String[4];
// Sets a title for the Inbox in expanded layout
events[0] = message.substring(0, 15);
events[1] = message.substring(15, 35);
events[2] = message.substring(35, 55);
events[3] = message.substring(55, 75);
inboxStyle.setBigContentTitle("Event tracker details:");
// Moves events into the expanded layout
for (int i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
builder.setSmallIcon(R.drawable.icon)
.setContentTitle("Event tracker"")
.setContentText("Events received")
.setWhen(System.currentTimeMillis()).setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_MAX)
.setStyle(inboxStyle);
Notification notification = builder.build();
notificationManager.notify(1, notification);
}
but application getting crash when new message arrive. How to change second or third function?