SetInexactRepeating警报不起作用

时间:2015-07-02 10:04:30

标签: android

我想在一周的某一天发出警报。例如,每周一下午4:30。

以下代码是我为此所写的内容,但它不起作用。我做错了什么?

public void setAlarm(int day,int hour,int minit) {

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE,minit );
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.DAY_OF_WEEK, day);

    Intent intent = new Intent(this, MyBroadcastReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
        this.getApplicationContext(), 234324243, intent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    Long alarmTime = cal.getTimeInMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, alarmTime,
                                     24 * 60 * 60 * 1000 *7 , pendingIntent);

}

0 个答案:

没有答案