gpt4 book ai didi

Android:未点击的通知超时

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

我将在周末发布通知。如果在一定时间后没有看到/点击通知,我希望它自己消失。我找不到任何方法来在 NotificationCompat.Builder 表达式中设置超时或类似的东西。这是(非常正常的通知生成器)代码:

Intent myIntent = new Intent(context, MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.not_bar_small_icon)
.setColor(ContextCompat.getColor(context, R.color.Green))
.setContentTitle(context.getResources().getString(R.string.strNotificationTitle))
.setContentText(context.getResources().getString(R.string.strNotificationMessage))
.setContentIntent(pendingIntent);

NotificationManager notifyManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notifyManager.notify(MY_NOTIFICATION_ID, mBuilder.build());

这可以做到吗?

解决方案更新:

使用下面评论中建议的 Aleksandar 链接解决。

最佳答案

https://developer.android.com/reference/android/app/Notification.Builder.html#setTimeoutAfter(long)

您可以指定一个持续时间(以毫秒为单位),如果该通知尚未取消,则在该时间过后应取消该通知。

关于Android:未点击的通知超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39228977/

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