Java.lang.IllegalArgumentException: Android Studio cannot connect to the mobile calendar - android

I don't know how to solve it. Please help me in solving this issue. Is the format of DateTime correct? Please help, thanks so much, much of appreciation. I have tried to solve it but doesn't work.
addToCalendar(getApplicationContext(), "hello","2012/10/10 10:05:33" );
}
public static void addToCalendar(Context oContext, final String title, final String eventStartDate)
{
String eventUriString = null;
long startDate = new Date(eventStartDate).getTime();
long endDate = new Date(eventStartDate).getTime() + 1000 * 60 * 60; // For next 1hr
TimeZone timeZone = TimeZone.getDefault();
ContentValues eventValues = new ContentValues();
if (Build.VERSION.SDK_INT >= 1 && Build.VERSION.SDK_INT < 20)
{
eventUriString = "content://com.android.calendar/events";
eventValues.put("calendar_id", 1);
eventValues.put("title", title);
eventValues.put("description", "");
eventValues.put("eventLocation", "");
eventValues.put("dtstart", startDate);
eventValues.put("dtend", endDate);
eventValues.put("eventStatus", "");
eventValues.put("visibility", 3);
eventValues.put("transparency", 0);
eventValues.put("hasAlarm", 1);
Uri eventUri = oContext.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
reminderValues.put("minutes", 5);
reminderValues.put("method", 1);
oContext.getApplicationContext().getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}
else if (Build.VERSION.SDK_INT >= 14 )
{
eventValues.put(CalendarContract.Events.DTSTART, startDate);
eventValues.put(CalendarContract.Events.DTEND, endDate);
eventValues.put(CalendarContract.Events.TITLE, title);
eventValues.put(CalendarContract.Events.DESCRIPTION, "");
eventValues.put(CalendarContract.Events.CALENDAR_ID, 3);
eventValues.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
oContext.getApplicationContext().getContentResolver().insert(CalendarContract.Events.CONTENT_URI, eventValues);
}
Toast.makeText(oContext, "Event Created on : " + startDate, Toast.LENGTH_SHORT).show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
error log
04-10 13:41:50.861 14823-14823/com.example.lean.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.lean.myapplication, PID: 14823
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lean.myapplication/com.example.lean.myapplication.MyActivity}: java.lang.IllegalArgumentException: Event values must include an eventTimezone
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
at android.app.ActivityThread.access$800(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1221)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5094)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Event values must include an eventTimezone
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:468)
at android.content.ContentResolver.insert(ContentResolver.java:1190)
at com.example.lean.myapplication.MyActivity.addToCalendar(MyActivity.java:66)
at com.example.lean.myapplication.MyActivity.onCreate(MyActivity.java:35)
at android.app.Activity.performCreate(Activity.java:5249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1096)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
            

The error tells you what is wrong: "Event values must include an eventTimezone"
Just add the following to your ContentValues variable:
eventValues.put("eventTimezone", TimeZone.getDefault().getID());

Related

Issue in Adding Calendar Event in Android M

I am using a code to add an event to the device's calendar. The code works fine in all the Android versions except Android M.The event when being added on Android M shows as a birthday instead of an event. Please help on how can this issue be fixed.
The code being used is as follows
// Add event to calendar
try {
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, startDateInMilliSeconds);
values.put(CalendarContract.Events.DTEND, endDateInMilliSeconds);
values.put(CalendarContract.Events.TITLE, title);
values.put(CalendarContract.Events.DESCRIPTION, description);
if (location != null && (!TextUtils.isEmpty(location))) {
values.put(CalendarContract.Events.EVENT_LOCATION, location);
}
values.put(CalendarContract.Events.CALENDAR_ID, 1);
values.put(CalendarContract.Events.EVENT_TIMEZONE, Calendar.getInstance()
.getTimeZone().getID());
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
// Save the eventId into the Task object for possible future delete.
long eventId = Long.parseLong(uri.getLastPathSegment());
Uri openCalendarEvent = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId);
Intent calIntent = new Intent(Intent.ACTION_VIEW).setData(uri);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startDateInMilliSeconds);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endDateInMilliSeconds);
calIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(calIntent);
} catch (Exception e) {
e.printStackTrace();
}
try below method # Himmat
public void addReminder() {
Intent calIntent = new Intent(Intent.ACTION_EDIT);
calIntent.setData(CalendarContract.Events.CONTENT_URI);
calIntent.setType("vnd.android.cursor.item/event");
calIntent.putExtra(CalendarContract.Events.TITLE, e.getName());
calIntent.putExtra(CalendarContract.Events.EVENT_LOCATION, e.getLocation());
calIntent.putExtra(CalendarContract.Events.DESCRIPTION, e.getDescription());
Calendar calStart=Calendar.getInstance();
if(Validator.isNotNull(e.getStartDate())) {
calStart.setTime(e.getStartDate());
}
calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
calStart.getTimeInMillis());
Calendar calEnd=Calendar.getInstance();
if(Validator.isNotNull(e.getEndDate())) {
calEnd.setTime(e.getEndDate());
}
calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
calEnd.getTimeInMillis());
calIntent.putExtra(CalendarContract.EXTRA_CUSTOM_APP_URI,
e.getRegistrationLink());
startActivity(calIntent);
}

android permissions READ_CALENDAR & WRITE_CALENDAR

even though i have declared the uses-permissions in the manifest, it gives me an error saying i need to add the permissions.
android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="groep2.project4">
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<uses-permission-sdk-23 android:name="android.permission.READ_CALENDAR"/>
<uses-permission-sdk-23 android:name="android.permission.WRITE_CALENDAR"/>
error:
FATAL EXCEPTION: main
Process: groep2.project4, PID: 3188
java.lang.SecurityException: Permission Denial:
opening provider com.android.providers.calendar.CalendarProvider2
from ProcessRecord{81d3d48 3188:groep2.project4/u0a58} (pid=3188, uid=10058)
requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778)
at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1999)
at android.content.ContentResolver.acquireProvider(ContentResolver.java:1421)
at android.content.ContentResolver.insert(ContentResolver.java:1225)
at groep2.project4.Fragments.pushAppointmentsToCalendar.pushAppointmentsToCalender(pushAppointmentsToCalendar.java:50)
at groep2.project4.Fragments.TimePickerFragment.makeReminder(TimePickerFragment.java:46)
at groep2.project4.Fragments.TimePickerFragment.onTimeSet(TimePickerFragment.java:41)
at android.app.TimePickerDialog.onClick(TimePickerDialog.java:145)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:163)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
and here is the pushappointmentstocalendar.java
package groep2.project4.Fragments;
import android.app.Activity;
import android.content.ContentValues;
import android.net.Uri;
/**
* Created by Dennis on 28-6-2016.
*/
public class pushAppointmentsToCalendar {
public static long pushAppointmentsToCalender(Activity curActivity, String title, String addInfo, String place, int status, long startDate, boolean needReminder, boolean needMailService) {
/***************** Event: note(without alert) *******************/
String eventUriString = "content://com.android.calendar/events";
ContentValues eventValues = new ContentValues();
eventValues.put("calendar_id", 1);
eventValues.put("title", title);
eventValues.put("description", addInfo);
eventValues.put("eventLocation", place);
long endDate = startDate + 1000 * 60 * 60; // For next 1hr
eventValues.put("dtstart", startDate);
eventValues.put("dtend", endDate);
eventValues.put("allDay", 0);
eventValues.put("eventStatus", status);
eventValues.put("eventTimezone", "UTC/GMT +2:00");
/*eventValues.put("visibility", 3); // visibility to default (0),
// confidential (1), private
// (2), or public (3):
eventValues.put("transparency", 0); // You can control whether
// an event consumes time
// opaque (0) or transparent
// (1).
*/
eventValues.put("hasAlarm", 1); // 0 for false, 1 for true
Uri eventUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
if (needReminder) {
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
reminderValues.put("minutes", 5); // Default value of the
// system. Minutes is a
// integer
reminderValues.put("method", 1); // Alert Methods: Default(0),
// Alert(1), Email(2),
// SMS(3)
Uri reminderUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}
/***************** Event: Meeting(without alert) Adding Attendies to the meeting *******************/
if (needMailService) {
String attendeuesesUriString = "content://com.android.calendar/attendees";
/********
* To add multiple attendees need to insert ContentValues multiple
* times
***********/
ContentValues attendeesValues = new ContentValues();
attendeesValues.put("event_id", eventID);
attendeesValues.put("attendeeName", "xxxxx"); // Attendees name
attendeesValues.put("attendeeEmail", "yyyy#gmail.com");// Attendee
// E
// mail
// id
attendeesValues.put("attendeeRelationship", 0); // Relationship_Attendee(1),
// Relationship_None(0),
// Organizer(2),
// Performer(3),
// Speaker(4)
attendeesValues.put("attendeeType", 0); // None(0), Optional(1),
// Required(2), Resource(3)
attendeesValues.put("attendeeStatus", 0); // NOne(0), Accepted(1),
// Decline(2),
// Invited(3),
// Tentative(4)
Uri attendeuesesUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(attendeuesesUriString), attendeesValues);
}
return eventID;
}
}
i cant figure out why it doesn't work. ive even tried adding the other SDK version of the permission but it still didn't work.
Once you are targeting android SDK 23 you should work with RunTime permissions, below is a simple method to help you on getting started.
private void checkPermissions(int callbackId, String... permissionsId) {
boolean permissions = true;
for (String p : permissionsId) {
permissions = permissions && ContextCompat.checkSelfPermission(this, p) == PERMISSION_GRANTED;
}
if (!permissions)
ActivityCompat.requestPermissions(this, permissionsId, callbackId);
}
You can use it like this:
final int callbackId = 42;
checkPermission(callbackId, Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR);
The requestPermissions method returns a callback in witch you can proceed to deal with the permissions being denied or accepted:
#Override
public void onRequestPermissionsResult(int callbackId,
String permissions[], int[] grantResults) {...}

How to add multiple event to android marshmallow Calendar?

Events are adding to calendar properly till api 22.
I have also implemented run- time permissions for Marshmallow , Calender permission is allowed in Phone setting for my application is clearly visible.
But still nothing is updating on phone calendar and also app giving no error or warning.
Below is my method to add event programatically on phone calendar.
private void addEventToCalender(Activity ourActivity, String title, String desc, String place, int status, long startDate, long endDte, boolean needReminder, boolean needMailService) {
try {
String eventUriString = "content://com.android.calendar/events";
ContentValues eventValues = new ContentValues();
eventValues.put("calendar_id", 1); // id, We need to choose from // our mobile for primary its 1
eventValues.put("title", "My Title");
eventValues.put("description","My Description" );
eventValues.put("eventLocation", "Noida,UP ";
eventValues.put("dtstart", startDate);
eventValues.put("dtend", endDte);
eventValues.put("allDay", 1); // 1 for whole day
//eventValues.put("rrule", "FREQ=YEARLY");
// values.put("allDay", 1); //If it is bithday alarm or such
// kind (which should remind me for whole day) 0 for false, 1
// for true
eventValues.put("eventStatus", 1); // This information is
// sufficient for most
// entries tentative (0),
// confirmed (1) or canceled
// (2):
eventValues.put("eventTimezone", "UTC/GMT " + Constants.tzone);
eventValues.put("hasAlarm", 1); // 0 for false, 1 for true
Uri eventUri = this.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
Log.i("eventID", eventID + "");
showSnackBar("Event added to calender successfuly.");
} catch (Exception ex) {
Log.e("error", "Error in adding event on calendar" + ex.getMessage());
showSnackBar("Ünable to add event to calender!");
}
}
May be you want to use inside Fragment .
at first use :
super.requestPermissions( new String[]{Manifest.permission.WRITE_CALENDAR}, MY_PERMISSIONS_REQUEST_WRITE_CALENDAR);
Inside fragment, you need to call:
FragmentCompat.requestPermissions(permissionsList, RequestCode)
Note:
ActivityCompat.requestPermissions(Activity, permissionsList, RequestCode);
add this library for FragmentCompat class in app.gradle.
compile 'com.android.support:support-v13:version_of_library'

Android Add Event to Calendar using Intent, get EventID

I'm trying to add event through an calendar intent. However, I can't figure out how to get the event ID of the event just added.
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", sdate.getTime());
intent.putExtra("endTime", edate.getTime());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("title", "A Test Event from android app");
intent.putExtra("description", "Description here");
intent.putExtra("eventLocation", "location here here here");
I read extensively on other resources and can't seem to find an answer. I tried startActivityForResult but I can't seem to get it work. Other methods I try can't seem to check for it until the activity ends.
Is there any other way to get the event ID after the event has been added to the calendar? I need to use the intent method for this.
Try this one solution:
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
public class CalenderUtils {
/**
* Add a new event into a native Google calendar. Add alert notification by setting <code>isRemind</code> as <code>true</code>.
* #param cr - ContentResolver
* #param title - Event title
* #param addInfo - Event description
* #param place - Event place
* #param status - <code>int</code> This information is sufficient for most entries: tentative (0), confirmed (1) or canceled (2):
* #param startDate - <code>long</code> event start time in mls
* #param isRemind - <code>boolean</code> need to remind about event before?
* #param isMailService - <code>boolean</code>. Adding attendees to the meeting
* #return <code>long</code> eventID
*/
public static long addEventToCalender(ContentResolver cr, String title, String addInfo, String place, int status,
long startDate, boolean isRemind, boolean isMailService) {
String eventUriStr = "content://com.android.calendar/events";
ContentValues event = new ContentValues();
// id, We need to choose from our mobile for primary its 1
event.put("calendar_id", 1);
event.put("title", title);
event.put("description", addInfo);
event.put("eventLocation", place);
event.put("eventTimezone", "UTC/GMT +2:00");
// For next 1hr
long endDate = startDate + 1000 * 60 * 60;
event.put("dtstart", startDate);
event.put("dtend", endDate);
//If it is bithday alarm or such kind (which should remind me for whole day) 0 for false, 1 for true
// values.put("allDay", 1);
event.put("eventStatus", status);
event.put("hasAlarm", 1);
Uri eventUri = cr.insert(Uri.parse(eventUriStr), event);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
if (isRemind) {
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
// Default value of the system. Minutes is a integer
reminderValues.put("minutes", 5);
// Alert Methods: Default(0), Alert(1), Email(2), SMS(3)
reminderValues.put("method", 1);
cr.insert(Uri.parse(reminderUriString), reminderValues); //Uri reminderUri =
}
if (isMailService) {
String attendeuesesUriString = "content://com.android.calendar/attendees";
/********* To add multiple attendees need to insert ContentValues multiple times ***********/
ContentValues attendeesValues = new ContentValues();
attendeesValues.put("event_id", eventID);
// Attendees name
attendeesValues.put("attendeeName", "xxxxx");
// Attendee email
attendeesValues.put("attendeeEmail", "yyyy#gmail.com");
// Relationship_Attendee(1), Relationship_None(0), Organizer(2), Performer(3), Speaker(4)
attendeesValues.put("attendeeRelationship", 0);
// None(0), Optional(1), Required(2), Resource(3)
attendeesValues.put("attendeeType", 0);
// None(0), Accepted(1), Decline(2), Invited(3), Tentative(4)
attendeesValues.put("attendeeStatus", 0);
cr.insert(Uri.parse(attendeuesesUriString), attendeesValues); //Uri attendeuesesUri =
}
return eventID;
}
}
i copypasted this class from my project so you are welcome to change names as you prefer.
As you notice here u receive id value after insertion.
If you need get reminderId or meeting id with attendees - you have to handle a return value from cr.insert... and then parce uri long id = Long.parseLong(uri.getLastPathSegment());
Here is an additional info: CalendarContract.Events and Calendar chapter

Not able to delete a reminder from Calendar in Android

I have added a calendar event programatically using the caledarcontract api and obtained a eventId. Similarly i added a reminder for this event and saved the reminderId too. Now i dont want a reminder for this event(or i would like to turn off the reminder), so i am trying to delete the reminder using the reminderId but i am not able to delete. I tried to delete the reminder using the eventId too but its not working.
public int AddEventToCalendar(String calendarId, Entity entity) {
// TODO Auto-generated method stub
ContentValues event = new ContentValues();
event.put("calendar_id", calendarId);
event.put("title", entity.description);
event.put("dtstart", System.currentTimeMillis());
event.put("dtend", System.currentTimeMillis() + 3600*1000);
event.put("allDay", 0);
//status: 0~ tentative; 1~ confirmed; 2~ canceled
event.put("eventStatus", 1);
//0~ default; 1~ confidential; 2~ private; 3~ public
event.put("visibility", 0);
//0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
event.put("transparency", 0);
//0~ false; 1~ true
event.put("hasAlarm", 1);
Uri add_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
add_eventUri = Uri.parse("content://com.android.calendar/events");
} else {
add_eventUri = Uri.parse("content://calendar/events");
}
Uri l_uri = context.getContentResolver().insert(add_eventUri, event);
if(l_uri != null)
{
long eventID = Long.parseLong(l_uri.getLastPathSegment());
return (int) eventID;
}
else
return 0;
}
public int AddReminderOnEvent(Entity entity)
{
if(entity.eventId != 0)
{
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", entity.eventId);
reminderValues.put("method", 1);// will alert the user with a reminder notification
reminderValues.put("minutes", 0);// number of minutes before the start time of the event to fire a reminder
Uri reminder_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
reminder_eventUri = Uri.parse("content://com.android.calendar/reminders");
} else {
reminder_eventUri = Uri.parse("content://calendar/reminders");
}
Uri r_uri = context.getContentResolver().insert(reminder_eventUri, reminderValues);
if(r_uri != null)
{
long reminderID = Long.parseLong(r_uri.getLastPathSegment());
return (int) reminderID;
// Toast.makeText(getApplicationContext(), "Event Created Successfully", Toast.LENGTH_LONG).show();
}
else
return 0;
}
else
{
return 0;
}
}
public boolean DeleteReminderOnTask(int eventId, int reminderId) {
// TODO Auto-generated method stub
Uri delete_reminderUri;
if (Build.VERSION.SDK_INT >= 8) {
delete_reminderUri = Uri.parse("content://com.android.calendar/reminders");
} else {
delete_reminderUri = Uri.parse("content://calendar/reminders");
}
delete_reminderUri = ContentUris.withAppendedId(delete_reminderUri, reminderId);
int rows = context.getContentResolver().delete(delete_reminderUri,null , null);
if(rows > 0)
return true;
else
return false;
}
After executing this code everytime the rows returns 0 meaning that no rows have been altered. And the reminder comes up exactly at the appropriate time. How to delete the reminder from the calendar without deleting the event?
I'm not sure which SDK version you're running against when failing, but this code (which is essentially the same as yours, less the version check) works for me:
Uri reminderUri = ContentUris.withAppendedId(
CalendarContract.Reminders.CONTENT_URI, reminderId);
int rows = contentResolver.delete(reminderUri, null, null);
I got reminderId by querying the event's reminders:
String[] projection = new String[] {
CalendarContract.Reminders._ID,
CalendarContract.Reminders.METHOD,
CalendarContract.Reminders.MINUTES
};
Cursor cursor = CalendarContract.Reminders.query(
contentResolver, eventId, projection);
while (cursor.moveToNext()) {
long reminderId = cursor.getLong(0);
int method = cursor.getInt(1);
int minutes = cursor.getInt(2);
// etc.
}
cursor.close();
This might not be the only or best way, but all I could figure out was how to remove all reminders for an event. I don't know of a way to remove just one reminder.
//What we want to update
ContentValues values = new ContentValues();
values.put(Events.HAS_ALARM, 0);
//We're setting the event to have no alarms
int result = getContentResolver().update(
Events.CONTENT_URI,
values,
Events._ID + " = ?",
new String[]{"44"}
);
Unfortunately, this removes all reminders, but I'm not sure multiple reminders are really supported by Android 14+ or most calendar providers (e.g. Exchange). The calendar app in ICS only allows adding one reminder (despite saying "Add Reminders").
And if i use another application such as Business Calendar to add multiple reminders, when I check in Exchange, it only shows ones reminder. It does show multiple reminders in the calendar app but only on that device, not on other devices, so multiple reminders seem to be local only.

Categories

Resources