其他分享
首页 > 其他分享> > 如何使用android的Notification Inbox风格?

如何使用android的Notification Inbox风格?

作者:互联网

我不知道如何准确使用通知收件箱样式.我刚刚尝试了下面的代码,它在Notification.InboxStyle()中显示错误.我做错了什么?任何人都可以帮我解决这个问题吗?这是我的代码..

  private void generateNotification(Context context, String message) {
    System.out.println(message+"++++++++++2");
    int icon = R.drawable.ic_message;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.message_title);
    String subTitle = context.getString(R.string.message_subtitle);
    Intent notificationIntent = new Intent(context, Output.class);
    notificationIntent.putExtra("content", message);
    PendingIntent intent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    Notification base = new Notification.Builder(context)
    .setTicker(message)
    .setSmallIcon(icon)
    .setWhen(when)
    .setContentTitle(title)
    .setContentText(subTitle)
    .setNumber(4)
    .setContentIntent(intent)
    .build();

    Notification notification = new Notification.InboxStyle(base)
    .addLine("First Message")
    .addLine("Second Message")
    .addLine("Third Message")
    .addLine("Fourth Message")
    .setBigContentTitle("Here Your Messages")
    .setSummaryText("+3 more")
    .build();

    //To play the default sound with your notification:
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);



}

提前致谢.

解决方法:

构造函数是

Notification.InboxStyle(Notification.Builder builder)

而且你正在传递通知.
请改为喜欢这样

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();

标签:android,styles,notifications,inbox
来源: https://codeday.me/bug/20190529/1175639.html