gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:01:28 24 4
gpt4 key购买 nike

这是我的代码:

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

设备是运行 Android 版本 4.4.2 的 S3。

为什么未应用 InboxStyle?

最佳答案

也许你可以试试这个:

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

关于Android Notification.InboxStyle 仍然显示默认通知布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31390803/

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