【发布时间】:2014-05-18 14:40:42
【问题描述】:
我有以下代码应该在 2 天后触发警报。但是它每 2 小时触发一次,一些用户说他们也每 5 分钟触发一次。
settingDB.updateSetting("Notification",1);
Calendar Calendar_Object = Calendar.getInstance();
Calendar_Object.set(Calendar.HOUR_OF_DAY, 10);
Calendar_Object.set(Calendar.MINUTE,01);
Calendar_Object.set(Calendar.SECOND, 0);
//Calendar_Object.set(Calendar.DAY_OF_WEEK, 1);
// MyView is my current Activity, and AlarmReceiver is the
// BoradCastReceiver
Intent myIntent = new Intent(Setting.this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Setting.this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
//Log.w("alarm set for " , Calendar_Object.getTime().toString ());
/*
* The following sets the Alarm in the specific time by getting the long
* value of the alarm date time which is in calendar object by calling
* the getTimeInMillis(). Since Alarm supports only long value , we're
* using this method.
* 3*1000*24*3600
*/
//alarmManager.setRepeating(AlarmManager.RTC, Calendar_Object.getTimeInMillis(),3600*1000**24,pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC, Calendar_Object.getTimeInMillis(), 86400000*2, pendingIntent);
你能帮我解决这个问题吗?
【问题讨论】:
标签: android alarmmanager