安卓:未点击通知超时时间

4

我将在周末发布通知。如果通知在一定时间内未被查看/点击,我希望它能自动消失。

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在下面评论中提供的链接解决了问题。


AlarmManager 可以帮助。 - Prashant
2
@Prashant 是正确的。 请查看:https://dev59.com/qoDaa4cB1Zd3GeqP_As3 - Lexandar
1个回答

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接