How to create Recurring of Alarm in Android After taking user input?

心已入冬 提交于 2019-12-14 03:08:18

问题


I am an android developer.I am making an application in which I have to take user input like 8:00,9:00,10:00 etc and I have to set alarm for 20 or 30 days for each time user enter .A user can enter two or three or any times the timings.I know there is a function

alarm.setRepeating(AlarmManager.RTC,System.currentTimeMillis()+timeinminutes*60*1000,30*1000, pintent);

But I have to set the alarm for ever or days entered by user .So can any body tell me .How can I do this .


回答1:


the following code help you,firstWake the app will run at very fast time,you can specify as your requirements

AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

long interval = android.text.format.DateUtils.DAY_IN_MILLIS*20;//or 30

long firstWake = System.currentTimeMillis() ;

am.setRepeating(AlarmManager.RTC,firstWake, interval, pendingIntent);



回答2:


Maybe you can use another nonrepeating alarm for 20 or 30 days that stops repeating alarms.



来源:https://stackoverflow.com/questions/6591592/how-to-create-recurring-of-alarm-in-android-after-taking-user-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!