Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old September 15th, 2011, 09:06 PM   #1 (permalink)
Junior Member
 
Join Date: Jul 2011
Posts: 27
 
Device(s):
Thanks: 9
Thanked 2 Times in 2 Posts
Unhappy How to repeat the alarm for between 1 to 60 days at a particular time ?

Hi,
I have to repeat alarm for between 1 day to 60 days. For example, the user can be able to repeat alarm after every 5 days, 10 days or 60 days (maximum).

Option1 ( Implemented Code
-----------------------------
alarmmanager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ (durationInDays * 24 * 3600 * 1000), (durationInDays * 24 * 3600 * 1000), pIntent);

Note: But it is working fine but it supports maximum 10 days(appx) repeating only after that "(durationInDays * 24 * 3600 * 1000)" it goes into -ve value so, I am unable to set maximum 60 days alarm repeatedly. AlarmManager class only supports a long value for choosing the interval between the execution of the pending intent.

Is there any other option to set repeat alarm for the no of days ?


Option 2 ( Implemented Code:
-------------------------------
Date futureDate = new Date(new Date().getTime() + (86400000 * durationInDays));
Date dateInterval = new Date(86400000 * durationInDays);
am.setRepeating(AlarmManager.RTC_WAKEUP, futureDate.getTime(), dateInterval.getTime(), pendingIntent);

Note: We set repeating alarm maximum every 24 days but when i give (durationInDays = 25; // in Days) then it takes -ve values.

Can I set repeating alarm with the help of Calender?

Please help me by piece of code.


Thanks in Advance,
Andy

Arthur Andy is offline  
Last edited by Arthur Andy; September 15th, 2011 at 11:42 PM.
Reply With Quote
Sponsors
Old September 21st, 2011, 12:56 AM   #2 (permalink)
Junior Member
 
Join Date: Jul 2011
Posts: 27
 
Device(s):
Thanks: 9
Thanked 2 Times in 2 Posts
Default

Hi,
I got one example regarding set alarm event using calendar.


================================================== =====
Button clickMe = (Button) findViewById(R.id.set_event);
clickMe.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Cursor cursor = getContentResolver().query(Uri.parse("content://calendar/calendars"),
new String[] { "_id", "displayName" }, "selected=1", null, null);
if (cursor != null && cursor.moveToFirst()) {
String[] calNames = new String[cursor.getCount()];
int[] calIds = new int[cursor.getCount()];
for (int i = 0; i < calNames.length; i++) {
// retrieve the calendar names and ids
calIds[i] = cursor.getInt(0);
calNames[i] = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();
if (calIds.length > 0) {
// further work
}
// note the URI
ContentValues event = new ContentValues();
int cal_id = calIds[0];
event.put("calendar_id", cal_id);
event.put("title", "Event Demo");
event.put("description", "Wedding party");
event.put("eventLocation", "New York");
event.put("eventStatus", 1);
event.put("visibility", 0);
event.put("transparency", 0);
event.put("hasAlarm", 1);


Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

Date dd = new Date("2011/02/17 05:07:00");
cal.set(111 + 1900, 01, 25, 12, 30, 00);

event.put("dtstart", cal.getTimeInMillis());
Calendar endCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
endCal.set(111 + 1900, 01, 25, 18, 30, 00);
event.put("dtend", endCal.getTimeInMillis());

Uri eventsUri = Uri.parse("content://calendar/events");
Uri url = getContentResolver().insert(eventsUri, event);
}


}
});
================================================== =====

It is working fine I am able to add event into Calendar event list. But Notification or alarm is not coming on that set time but only it show ur event was added into Calendar event list.

"I can check the set event into device Calendar."

Please help where I am doing mistake by piece of Codes. I am still waiting for your response.


Thanks,
Andy
Arthur Andy is offline  
Reply With Quote
Reply

Bookmarks

Tags
android, java


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 11:47 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo