AlarmManager第二天没有开火

时间:2014-12-22 13:00:09

标签: java android alarmmanager

我已将AlarmManager设置为特定时间并更新旧版本的时间。但问题是AlarmManager没有在下一个日期开火,但是如果我手动更改日期然后它的工作但是如果自动更改那么它不会触发

 AlarmManager alarm = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
    Intent intent = new Intent(context, BrSendSMS.class);
    intent.putExtra("schedulesmsid", schedulesmsid);
    int schedulelistid = -1;
    try
    {
        schedulelistid = Integer.valueOf(schedulesmsid);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, schedulelistid, intent, Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        alarm.cancel(pendingIntent);
        alarm.set(AlarmManager.RTC_WAKEUP, scheduledtime, pendingIntent);
    } catch (NumberFormatException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

1 个答案:

答案 0 :(得分:0)

尝试使用setRepeating ...

使用以下代码...

                Calendar alarmTime=Calendar.getInstance();  
                alarmTime.set(Calendar.HOUR_OF_DAY,18);
                alarmTime.set(Calendar.MINUTE, 0);
                alarmTime.set(Calendar.SECOND, 0);          
                Intent alarmIntent = new Intent(MainActivity.this,AlarmReceiver.class);
                PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, alarmIntent, 0);
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                Long time = alarmTime.getTimeInMillis() + (24 * 60 * 60 * 1000 * 2);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time,24 * 60 * 60 * 1000 * 2, pendingIntent);

我希望它会对你有所帮助。