Reputation: 37
Please Help..!
I'm trying to set multiple events/reminders in app. for that I have written the following code (Please see the code below) there is no error in my code, code is getting run successfully but after running my code when I open my Calendar to view the Event, I found that there is no event set..! I have referred answers suggested on this link but still not working.. My Code to set reminder is
private void addReminder(int statrYear, int startMonth, int startDay, int startHour, int startMinut, String title)
{
long calID = 3;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
// Sets the year, month, day of the month, hour of day, and minute fields.
beginTime.set(statrYear, startMonth, startDay, startHour, startMinut); // set(int year, int month, int day, int hourOfDay, int minute).
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(statrYear, startMonth, startDay, startHour+1, startMinut);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "Multiple Event Test");
values.put(Events.DESCRIPTION, "My Calendar Test");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "Israel/tel-aviv");
Uri uri = cr.insert(Events.CONTENT_URI, values);
}
I have called this method 3 times (to set 3 reminders at a time) on button click event as-- (please see the following code)
multiEventbutton = (Button) findViewById(R.id.multi_event);
multiEventbutton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
int statrYear=2013, startMonth=9, startDay=21, startHour=9, startMinut=0;
String strRemindarTitle="Title";
for(int i=0; i<3; i++)
{
strRemindarTitle=strRemindarTitle+""+i+1;
addReminder(statrYear, startMonth, startDay, startHour, startMinut, strRemindarTitle);
startDay++;
Toast.makeText(getApplicationContext(), "Event "+(i+1)+" Date= "+startDay+"/"+startMonth+"/"+statrYear, Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "strReturnData= "+strReturnData, Toast.LENGTH_LONG).show();
}
}
});
Please Help...! Thanks..!
Upvotes: 0
Views: 2191
Reputation: 1790
I just tried this its working fine. Make sure the values and calendar_id is proper:
for(int i=0;i<=3;i++){
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2000, 1, i, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2000, 1, i, 8, 45);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "Jazzercise");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, 1);
values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
Uri uri = cr.insert(Events.CONTENT_URI, values);
// get the event ID that is the last element in the Uri
long eventID = Long.parseLong(uri.getLastPathSegment());
}
Upvotes: 2