Reputation: 25
I'm developing an application that can send a SMS in specified time, I have add some function on it, but i get stumped while i add function that can send a sms in every month on 14th, how can i make that function?
i have try the answer code on this link but didn't work.
I presume the problem is on the interval parameter in setRepeating function of AlarmManager class
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis(), interval , pendingIntent);
what the proper value of variable interval?
Upvotes: 0
Views: 2718
Reputation: 779
alarmManager .setInexactRepeating(AlarmManager.RTC_WAKEUP,
calendar1.getTimeInMillis() + AlarmManager.INTERVAL_DAY*30,
AlarmManager.INTERVAL_DAY*30, pendingIntent);
You can try like this
Upvotes: 0
Reputation: 7415
here interval is time in milliseconds between two alarms.
//e.g
long interval=5*60*1000;
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis(), interval , pendingIntent);
then my alarm will repeat every after 5 mins.
EDIT
int days=GetTotalDays(current_month);
interval=(days)*24*60*60*1000;
public int GetTotalDays(int current_month)
{
//here u can fetch current months total days
//suppose current month is 6(means july as it starts from 0)
//& u want to set alarm to next month(august)
//so get remaining days from calender of current month + day of next month
//e.g(14-7 to 14-8) so
//remaining days from calender of current month = 18(14-7 to 31-7)
//day of next month =14.
//so return would be (18+14-2=30).(-2.as it takes currentdate and nextdate also in calculation)
int currentdate=14;
int nextdate=14;
int totalDays=getDaysInMonthInPresentYear(6);
int myDays=(totalDays-currentdate)+nextdate;
return myDays-2;
}
public static int getDaysInMonthInPresentYear(int monthNumber)
{
int days=0;
if(monthNumber>=0 && monthNumber<12){
try
{
Calendar calendar = Calendar.getInstance();
int date = 1;
int year = calendar.get(Calendar.YEAR);
calendar.set(year, monthNumber, date);
days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
} catch (Exception e)
{
if(e!=null)
e.printStackTrace();
}
}
return days;
}
Upvotes: 1