如何添加Android Notification附加说明?

时间:2014-03-24 17:59:13

标签: android

我尝试了一个通知示例。

如何添加此图片等附加说明

enter image description here

我的通知代码

NotificationCompat.Builder  mBuilder = new NotificationCompat.Builder(this)
        .setContentTitle("New Message with implicit intent")
        .setContentText("New message from javacodegeeks received...")
        .setTicker("Implicit: New Message Received!")
        .setSmallIcon(MainActivity.NotiImage)
        .setAutoCancel( false )
        .setNumber( ++NotificationHelper.messagges )
        .setLargeIcon(BitmapFactory.decodeResource( getResources(), MainActivity.NotiImage ));

        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        String[] events = new String[3];
        events[0] = new String("1) Message for implicit intent");
        events[1] = new String("2) big view Notification");
        events[2] = new String("3) from javacodegeeks!");

        inboxStyle.setBigContentTitle("More Details:");
        for (int i=0; i < 9; i++) {
            inboxStyle.addLine("olkun " + i);
        }
        mBuilder.setStyle(inboxStyle);
        NotificationManager myNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        myNotificationManager.notify(1, mBuilder.build());

3 个答案:

答案 0 :(得分:3)

您想使用NotificationCompat.InboxStyle.setSummaryText()

inboxStyle.setSummaryText("Summary Text goes here");

developer guide中也描述为:

  

摘要文字

     

允许您在详细信息区域下方添加一行文字。

答案 1 :(得分:0)

我相信setSubText()是您要找的method

答案 2 :(得分:0)

你必须使用&#34;大画面风格&#34;像这样

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Event tracker")
.setContentText("Events received")
NotificationCompat.InboxStyle inboxStyle =
    new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle("Event tracker details:");
...
// Moves events into the big view
for (int i=0; i < events.length; i++) {

inboxStyle.addLine(events[i]);
}
// Moves the big view style object into the notification object.
mBuilder.setStyle(inBoxStyle);
...
// Issue the notification here.  

在事件数组中写下您想要的更新