通知收件箱风格时通知不过来获取更新 [英] Notification inbox style however gets updated when a notification comes
问题描述
我试图让我想要在一个引擎盖一切都会通知的通知的风格,他们将显示行明智的。如果新的通知到来时,它应该是根据第二最新。通知的名单应该是5,这意味着只有最新的5将会显示。
我用这低于code这一点,我不知道如何做到这一点,我想我的手StackBuilder但是太我得到的,这将产生更高的API比我现在用的工作之一。
NotificationManager notificationManager =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
意图notificationIntent =新意图(这一点,GcmActivity.class);
notificationIntent.putExtra(称号,消息类型);
notificationIntent.putExtra(信息,味精);
的PendingIntent意图= PendingIntent.getActivity(在此,0,notificationIntent,0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);NotificationCompat.Builder mBuilder =新NotificationCompat.Builder(本).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(我的使者)setContentText(信息)。
NotificationCompat.InboxStyle inboxStyle =新NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(信息+详细信息); inboxStyle.addLine(消息类型+:+ MSG);
mBuilder.setStyle(inboxStyle);
mBuilder.setContentIntent(意向);
mBuilder.setAutoCancel(真);
notificationManager.notify(的Integer.parseInt(0),mBuilder.build());
您能帮我实现这个
我知道我可以通过添加行的任何数量的同时创造做到这一点。
NotificationCompat.InboxStyle inboxStyle =新NotificationCompat.InboxStyle();
不过,我想,当我过会GCMIntentService被调用,这个名单将被更新。
我试着用下面这个code以及但是这并没有工作,要么
工作 NotificationManager notificationManager =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
意图notificationIntent =新意图(这一点,GcmActivity.class);
notificationIntent.putExtra(称号,消息类型);
notificationIntent.putExtra(信息,味精);
的PendingIntent意图= PendingIntent.getActivity(在此,0,notificationIntent,0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);NotificationCompat.Builder mBuilder =新NotificationCompat.Builder(
这一点).setAutoCancel(真)
.setContentTitle(我的使者)
.setSmallIcon(R.drawable.ic_launcher)
.setContentText(信息); NotificationCompat.InboxStyle inboxStyle =新NotificationCompat.InboxStyle();对于(INT J = 0; J< listMessage.size(); J ++)
inboxStyle.addLine(listMessage.get(J));
mBuilder.setStyle(inboxStyle);
mBuilder.setContentIntent(意向);
notificationManager.notify(0,mBuilder.build());
我有同样的问题,并坚持对数据库的通知,当一个新的到达加载它们,然后将其删除点击或删除固定它。
DatabaseHelper dbHelper =新DatabaseHelper(本);
光标通知= dbHelper.getAllNotifications();
NotificationCompat.Builder mBuilder = extractNotifications(标题,味精,contentIntent,通知);
dbHelper.insertNotification(标题+:+味精);私人NotificationCompat.Builder extractNotifications(字符串名称,弦乐味精,的PendingIntent contentIntent,光标通知){
NotificationCompat.Builder mBuilder;
mBuilder =
新NotificationCompat.Builder(本)
.setSmallIcon(R.drawable.ic_icon)
.setContentTitle(职称)
.setStyle(新NotificationCompat.BigTextStyle()
.bigText(NOTIFICAITONS))
.setContentText(MSG)
.setAutoCancel(真)
.setLights(Color.WHITE,1000,5000)
.setDefaults(Notification.DEFAULT_VIBRATE |
Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
.setContentIntent(contentIntent); NotificationCompat.InboxStyle inboxStyle =
新NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(NOTIFICAITONS);
而(notifications.moveToNext())
{
inboxStyle.addLine(notifications.getString(notifications.getColumnIndex(DatabaseHelper.NOTIFICATION_MESSAGE)));
}
inboxStyle.addLine(标题+:+味精);
mBuilder.setStyle(inboxStyle);
返回mBuilder;
I am trying to make a notification style where I want all notification would under one hood and they will be shown line wise. If a new notification comes, it should be under the second latest. The list of notification should be of 5, that means only latest 5 will be displayable.
I am using this below code for this, I don't know how to achieve this, I tried my hands StackBuilder too however I got that, this would work from higher API than I am using one now.
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, GcmActivity.class);
notificationIntent.putExtra("title", messagetype);
notificationIntent.putExtra("message", msg);
PendingIntent intent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("MY MESSENGER").setContentText("MESSAGES");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle("MESSAGES" + " Details");
inboxStyle.addLine(messagetype + ":" + msg);
mBuilder.setStyle(inboxStyle);
mBuilder.setContentIntent(intent);
mBuilder.setAutoCancel(true);
notificationManager.notify(Integer.parseInt("0"), mBuilder.build());
Can you help me achieving this
I know I can do this by adding any number of line while creating
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
However I want that when ever my GCMIntentService will be called, this list will be updated.
I tried the work using this below code as well however that did not work either
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, GcmActivity.class);
notificationIntent.putExtra("title", messagetype);
notificationIntent.putExtra("message", msg);
PendingIntent intent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setAutoCancel(true)
.setContentTitle("MY MESSENGER")
.setSmallIcon(R.drawable.ic_launcher)
.setContentText("MESSAGES");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
for(int j= 0; j<listMessage.size(); j++)
inboxStyle.addLine(listMessage.get(j));
mBuilder.setStyle(inboxStyle);
mBuilder.setContentIntent(intent);
notificationManager.notify(0, mBuilder.build());
I had the same issue and fixed it by persisting the notifications on the database to load them when a new one arrives, and delete them on click or delete.
DatabaseHelper dbHelper = new DatabaseHelper(this);
Cursor notifications = dbHelper.getAllNotifications();
NotificationCompat.Builder mBuilder = extractNotifications(title, msg, contentIntent, notifications);
dbHelper.insertNotification(title + ": " + msg);
private NotificationCompat.Builder extractNotifications(String title, String msg, PendingIntent contentIntent, Cursor notifications) {
NotificationCompat.Builder mBuilder;
mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_icon)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(NOTIFICAITONS))
.setContentText(msg)
.setAutoCancel(true)
.setLights(Color.WHITE, 1000, 5000)
.setDefaults(Notification.DEFAULT_VIBRATE |
Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
.setContentIntent(contentIntent);
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(NOTIFICAITONS);
while (notifications.moveToNext())
{
inboxStyle.addLine(notifications.getString(notifications.getColumnIndex(DatabaseHelper.NOTIFICATION_MESSAGE)));
}
inboxStyle.addLine(title + ": " + msg);
mBuilder.setStyle(inboxStyle);
return mBuilder;
这篇关于通知收件箱风格时通知不过来获取更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!