AlarmManager在模拟器中的特定时间运行

时间:2016-10-27 15:34:55

标签: java android alarmmanager

如果我设置HOUR = 11和MINUTE = 00,它在我的模拟器中不会在11:00运行,这里有什么问题吗?:

>>> hello = (
... "This paragraph forms "
... "a block of text, which "
... "can be short like this, "
... "or extremely long!"
... )
>>> print(hello)
This paragraph forms a block of text, which can be short like this, or extremely long!
>>> 

1 个答案:

答案 0 :(得分:0)

这个闹钟将在上午11点开始工作..

    Calendar cal = Calendar.getInstance();
    Intent intent = new Intent(this,  MyService.class);
    PendingIntent penintent = PendingIntent.getService(this, 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

      //Here I have set it to 11.00am

         Calendar cal = Calendar.getInstance();
         cal.set(Calendar.HOUR_OF_DAY, 11);
         cal.set(Calendar.MINUTE, 0);
         cal.set(Calendar.SECOND, 0);

        //set timer as a RTC Wakeup to alarm manager object
     alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY, penintent);

我建议,尝试使用此解决方案。