Android:未点击通知超时 [英] Android: Unclicked notification timeout
问题描述
我将在周末发布通知.如果在一段时间后未看到/点击通知,我希望它自行消失.我找不到在 NotificationCompat.Builder
表达式中设置超时或类似内容的任何方法.这是(非常正常的通知生成器)代码:
I'm launching a notification on the weekend. If the notification is not seen/clicked after a certain time, I would like it to disappear by itself.
I couldn't find any way to set a timeout or something of the sort within the NotificationCompat.Builder
expression. Here is the (quite normal notification builder) code:
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 链接解决.
Solved using Aleksandar's link suggested in the comment below.
推荐答案
https://developer.android.com/reference/android/app/Notification.Builder.html#setTimeoutAfter(long)
您可以指定一个持续时间(以毫秒为单位),在此之后应取消此通知(如果尚未取消).
you can specify a duration in milliseconds after which this notification should be canceled, if it is not already canceled.
这篇关于Android:未点击通知超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!