简体   繁体   English

发出多个通知Android

[英]Issuing multiple notifications Android

I am trying to issue multiple notifications (After one notification has been issued, I want to add up on that). 我正在尝试发出多个notifications (发出一个通知后,我想对此进行累加)。

I have been through the official docs, which describe that the notification number should be unique and should be used to update the notification. 我浏览过官方文档,这些文档描述通知号应该是唯一的,并且应该用于更新通知。 However I am finding it difficult to put a new line for a new notification (inboxStyle). 但是,我发现很难为新的notification新行(inboxStyle)。 Below is my code: 下面是我的代码:

public void notificationFetch(int number, String greeting, String header){


        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.addLine(Html.fromHtml("<i>italic</i> <b>bold</b>"));



        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setUsesChronometer(true).setTicker("tickerText").setStyle(inboxStyle)
                .setLights(Color.BLUE, 200, 300).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("Reminder").setContentText(header).setSubText(greeting).setNumber(number);





        Intent resultIntent = new Intent(this, MainActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(number, mBuilder.build());

    }

.setSubText() does the required trick of appending more text, however I don't get new lines? .setSubText()是否需要添加更多文本的技巧,但是我没有得到新行? Any ideas? 有任何想法吗?

示例图片:

The rows (M.Twain) is a problem issue with me, I want different lines for new notifications. 行(M.Twain)是我的问题,我希望新通知使用不同的行。

Right now I get everything in a single line. 现在,我将所有内容放在一行中。

Here is what I get right now: 这是我现在得到的:

在此处输入图片说明

try this 尝试这个

 Notification noti = new Notification.InboxStyle(
  new Notification.Builder()
     .setContentTitle("5 New mails from " + sender.toString())
     .setContentText(subject)
     .setSmallIcon(R.drawable.new_mail)
     .setLargeIcon(aBitmap))
  .addLine(str1)
  .addLine(str2)
  .setContentTitle("")
  .setSummaryText("+3 more")
  .build();

Here is the samples link 这是示例链接

http://developer.android.com/reference/android/app/Notification.InboxStyle.html http://developer.android.com/reference/android/app/Notification.InboxStyle.html

Try this way: 尝试这种方式:

Notification notification = new Notification.InboxStyle(new Notification.Builder(context)
.setTicker(message)
.setSmallIcon(icon)
.setWhen(when)
.setContentTitle(title)
.setContentText(subTitle)
.setNumber(4)
.setContentIntent(intent))
.addLine("First Message")
.addLine("Second Message")
.addLine("Third Message")
.addLine("Fourth Message")
.setBigContentTitle("Here Your Messages")
.setSummaryText("+3 more")
.build();

Also go to official docs for more information. 也可以去官方文档获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM