尝试使用通知收件箱样式在通知中显示更多类似于 GMAIL 应用的行,但它不起作用



这是我拥有的代码:

  NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
    inboxStyle.setBigContentTitle("Title - Notification");
    inboxStyle.setSummaryText("TEST");
    inboxStyle.addLine("LINE");
    Notification noti = new Notification.Builder(getActivity())
            .setContentTitle("PSNGR")
            .setContentText("PITSTOP BLA").setSmallIcon(R.drawable.notification_icon)
            .setStyle(inboxStyle)
            .setContentIntent(null).build();
    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notifManager.notify(0, noti);

,但收件箱通知中的任何内容都没有。我只得到psngr和pitstop bla,为什么是?

ps:也尝试使用BittextStyle()尝试,但也看不到:对于此代码:

 NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getActivity())
            .setContentTitle("PSNGR")
            .setSmallIcon(R.drawable.ic_launcher)
            .setStyle(new NotificationCompat.BigTextStyle().bigText("MATA"))
            .setStyle(new NotificationCompat.BigTextStyle().bigText("MATA2"))
            .setAutoCancel(true)
            .setContentIntent(null);
    notifManager.notify(0, notificationBuilder.build());

我只看到:" psngr"

我使用了远程视图,而不是普通通知:

 NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(getActivity()).setSmallIcon(R.drawable.ic_launcher);
    RemoteViews mContentView = new RemoteViews(getActivity().getPackageName(), R.layout.pitstop_notification);
    mContentView.setImageViewResource(R.id.image, R.drawable.notification_icon);
    mContentView.setTextViewText(R.id.title, "Custom notification");
    mContentView.setTextViewText(R.id.text, "This is a custom layout");
    mContentView.setTextViewText(R.id.text2, "This is a custom layout2");
    mBuilder.setContent(mContentView);
    notifManager.notify(0, mBuilder.build());

最新更新