android – 在特定时间每天重复报警(报警管理器)
作者:互联网
嗨,我希望我的应用程序每天在特定时间运行.为此,我使用下面的代码.但它只运行一次.这里的错误是怎么来实现这个任务的.
AlarmManager alarmMgr0 = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent0 = new Intent(this, ActivityStarter.class);
PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, intent0, 0);
Calendar timeOff9 = Calendar.getInstance();
timeOff9.set(Calendar.HOUR_OF_DAY, 16);
timeOff9.set(Calendar.MINUTE, 13);
timeOff9.set(Calendar.SECOND, 0);
alarmMgr0.setRepeating(AlarmManager.RTC_WAKEUP, timeOff9.getTimeInMillis(),24*60*60*1000,pendingIntent0);
请帮忙.
解决方法:
试试这个
alarmMgr0 .setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY,
AlarmManager.INTERVAL_DAY, intent);
参考this
标签:android,android-alarms 来源: https://codeday.me/bug/20190831/1777514.html