在特定时间显示通知

时间:2021-02-09 01:18:21

标签: java android-studio android-notifications android-calendar android-switch

我目前创建了一个通知,在选中开关时显示没有问题,但是我想创建一个 if 语句来设置显示通知的当前时间。我已经尝试了以下方法,但是测试时在下午 3 点 30 分没有显示通知,我是否遗漏了什么或我该怎么做?

public void onCheckedChanged(CompoundButton buttonView, boolean notificationSwitchisChecked) {
      if(notificationSwitchisChecked){
           Calendar.getInstance();
           if (Calendar.HOUR_OF_DAY == 15 && Calendar.MINUTE == 30 && Calendar.SECOND == 0){
             sendNotification(); // this method displays the notification no problem when checked
                }
           }

1 个答案:

答案 0 :(得分:0)

建议您了解事件侦听器并查看下面的堆栈答案:

Current time/date event listener