gpt4 book ai didi

android - 如何使用android使用通知收件箱样式?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:38:39 32 4
gpt4 key购买 nike

我不知道如何准确使用通知收件箱样式。我刚刚尝试了下面的代码,它在 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 - 如何使用android使用通知收件箱样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20681483/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com