在android中每隔5分钟不会重复闹钟

时间:2012-09-17 11:51:29

标签: android service alarmmanager

我想每5分钟重复一次闹钟,但不能正常工作。我的代码是

        hour = timePicker.getCurrentHour();
            minuts = timePicker.getCurrentMinute();
            Log.i("hour" + hour, "minits" + minuts);

            calSet.set(Calendar.HOUR_OF_DAY, hour);
            calSet.set(Calendar.MINUTE, minuts);
            calSet.set(Calendar.SECOND, 0);
            calSet.set(Calendar.MILLISECOND,0);

            Intent intent = new Intent(getBaseContext(),
                    AlarmBroadcastReceiver.class);
            final int _id = (int) System.currentTimeMillis();

            PendingIntent pendingIntent = PendingIntent.getBroadcast(
                    getBaseContext(), _id, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

            if (snooze.isChecked()) {
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                        calSet.getTimeInMillis(), 5*60*1000, pendingIntent);
            } else {

                 alarmManager.set(AlarmManager.RTC_WAKEUP,
                         calSet.getTimeInMillis(),pendingIntent);
            }

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calSet.getTimeInMillis(),5 * 1000,pendingIntent);

1 个答案:

答案 0 :(得分:1)

试试这个。

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(), 5*60*1000, pendingIntent);