Android Notification.InboxStyle仍显示默认通知布局

时间:2015-07-13 18:30:10

标签: android notifications

这是我的代码:

public static void pushNotification(Activity currentActivity, String title, String content[]){

    NotificationManager nm = (NotificationManager) currentActivity.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent resultIntent = new Intent(currentActivity.getBaseContext(), FileSharingActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(currentActivity);
    stackBuilder.addParentStack(FileSharingActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);


    nm.notify(nextId++, new Notification.InboxStyle(new Notification.Builder(currentActivity.getBaseContext())
                                                    .setTicker("Ticker")
                                                    .setSmallIcon(R.drawable.ic_launcher)
                                                    .setWhen(System.currentTimeMillis())
                                                    .setContentTitle("Content title")
                                                    .setContentText("Content text")
                                                    .setNumber(4)
                                                    .setContentIntent(resultPendingIntent))
                                                    .addLine("First Message")
                                                    .addLine("Second Message")
                                                    .addLine("Third Message")
                                                    .addLine("Fourth Message")
                                                    .setBigContentTitle("Here Your Messages")
                                                    .setSummaryText("+3 more")
                                                    .build());
}

结果如下: enter image description here

设备是S3运行Android版本4.4.2。

为什么不应用InboxStyle?

2 个答案:

答案 0 :(得分:1)

也许你可以试试这个:

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

此处有更多信息:http://developer.android.com/reference/android/app/Notification.InboxStyle.html

编辑:

我在Android项目中这样做:

    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

    Notification n  = new Notification.Builder(this)
                    .setContentTitle(titel)
                    .setContentText(text)
                    .setTicker(ticker)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(pIntent)
                    .setAutoCancel(true)
                    .getNotification();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    n.flags |=Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, n); 

答案 1 :(得分:0)

我不得不向下滑动通知以查看扩展信息。

代码工作正常。