活动已经打开时,请勿启动通知

时间:2014-02-02 11:28:25

标签: android android-activity notifications alarmmanager

我设置一个AlarmManager每24小时打开一次通知 但每次我打开活动时,通知都会开始 那么如何设置它不显示活动已经打开时的通知?

这是我的AlarmManager代码:

AlarmManager alarmManager = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
        Intent intent = new Intent(this, myService.class);
        PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
        Calendar calendar = Calendar.getInstance();
        long when = calendar.getTimeInMillis();         // notification time
        calendar.set(Calendar.HOUR_OF_DAY, 20);
        calendar.set(Calendar.MINUTE, 00);
        calendar.set(Calendar.SECOND, 00);
        alarmManager.setRepeating(AlarmManager.RTC, when, 24*60*60*1000, pendingIntent);  //every 24 hours

谢谢,

1 个答案:

答案 0 :(得分:0)

当变量指向当前时间时,警报将在执行该部分时触发。更改何时到calendar.getTimeInMillis()。您的日历变量设置为当天的20小时,并在第二天重复。这是working copy