gpt4 book ai didi

android - 当新通知出现时,旧通知的标题和文本在 android 中被清除

转载 作者:搜寻专家 更新时间:2023-11-01 08:43:03 24 4
gpt4 key购买 nike

我正在创建一个在不同时间带有通知的应用程序。第一个通知在通知栏中显示正常,带有图标、标题和文本。但是当第二个通知到来时,第一个通知的标题和文本被清除,第二个显示。对于第三个通知,第二个通知的标题和文本将被清除,依此类推。我使用的代码是

        Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
long mNotificationId = System.currentTimeMillis();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setSound(uri);

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();

bigTextStyle.setBigContentTitle("Time to Sleep!!!");
bigTextStyle.bigText("A good laugh and a long sleep are the best cures in the doctor's book.");

mBuilder.setStyle(bigTextStyle);
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify((int)mNotificationId, mBuilder.build());

如有任何帮助,我们将不胜感激。提前致谢。

最佳答案

我认为您只是为 BigTextStyle 设置文本

同时为小值或默认设置设置值

例如

// Small - default style
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(context.getApplicationInfo().icon)
.setWhen(System.currentTimeMillis())
.setContentTitle(extras.getString("title"))
.setTicker(extras.getString("title"))
.setContentIntent(contentIntent);

只需检查 mNotificationId 值是否相同如果相同,您可以使用以下方法生成随机数

Random random = new Random();
int m = random.nextInt(9999 - 1000) + 1000;

然后使用这个m

mNotifyMgr.notify(m, mBuilder.build());

关于android - 当新通知出现时,旧通知的标题和文本在 android 中被清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30978844/

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