【发布时间】:2013-04-03 19:41:05
【问题描述】:
我需要在每天早上 5 点运行我的更新服务,以便在用户早上拿起手机时刷新数据。我到目前为止的代码是 -
Log.d(TAG, "setAutoRun");
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, RefreshIntentService.class);
PendingIntent pendingI = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar time = Calendar.getInstance();
time.setTimeInMillis(System.currentTimeMillis());
time.add(Calendar.SECOND, 60); // this was just to test out the alarm service
alarmMgr.set(AlarmManager.RTC, time.getTimeInMillis(), pendingI);
如何修改它以使其在每天早上 5 点运行? 我知道我可以设置一个间隔,让它在 X 分钟内再次运行,但如果用户不打开它,我怎么能在早上 5 点开始它。
谢谢
【问题讨论】:
标签: android date time alarmmanager