【问题标题】:Notification not coming when time is set in PM在 PM 中设置时间时没有通知
【发布时间】:2018-01-03 05:04:33
【问题描述】:

我的应用程序中有一个提醒,它将在计划警报前 15 分钟触发通知。我使用的是 24 小时格式,所以当我在早上设置闹钟时,通知即将到来,但是当我尝试在 12:00 之后设置闹钟时,比如 13:30,通知没有触发。

这是我的警报管理器:

public void saveChanges(Context context) {
        init(context);

        if (getReminderStatus) {
            Calendar calendar = Calendar.getInstance();
            //calendar.set(Calendar.DAY_OF_WEEK, workOutDays[i] + 1); //+1 because for android sunday is 1
            calendar.set(Calendar.HOUR_OF_DAY, getHours());
            Log.d("alarm","hours"+ String.valueOf(getHours()));
            calendar.set(Calendar.MINUTE,getMinutes());
            Log.d("alarm","minutes"+ String.valueOf(getMinutes()));
            alarmManager.cancel(pendingIntent);
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
        }
    }

报警接收器:

public void onReceive(Context context, Intent intent) {
        getDataFromSharedPrefrence();
        if(!isTodayRestDay() && getReminderStatus){
            NotificationFCM notificationFCM = FCMUtility.getFCM(getIntentData());
            FCMHelper.instance.displayFCM(notificationFCM,context);
        }
        //Toast.makeText(context,"show notification",Toast.LENGTH_SHORT).show();
    }

我也尝试调试,但是当在 PM 中设置警报时,控件没有进入 onReceive。在 PM 中设置时,我是否必须进行任何特定更改才能触发警报。

【问题讨论】:

    标签: android alarmmanager


    【解决方案1】:

    Calendar.HOUR_OF_DAYaccept 24 HOUR formate 所以你应该把 12 hours formate 改成 24 Hour Formate 传递给压延机。

     calendar.set(Calendar.HOUR_OF_DAY, hoursForDayin24hourFormate);
    

    【讨论】:

    • 那你为什么要添加PM? 24 小时制没有上午/下午。使用 SimpleDateFormate 记录您的日期/时间。
    • 抱歉给您带来了困惑。当我将时间设置为 13:00 时,警报没有触发
    • 如果您的 AlarmManager 代码正常工作,那么我认为 AM PM 没有任何区别。你可能错过了什么。在(dd/MM/yyyy hh/mm a) 中打印整个时间戳并检查日期。
    猜你喜欢
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多