Update and delete calendar events in android through my application

前端 未结 1 1499
挽巷
挽巷 2021-02-20 10:52

Can anybody show me how can i modify(Edit) and delete android calendar events which has been added by the user itself using my android application. I have tried

1条回答
  •  长情又很酷
    2021-02-20 11:13

    Take a look at this question: StackOverflow

    This code worked for me.

    Uri eventsUri = Uri.parse("content://com.android.calendar/events");
    ContentResolver cr = getContentResolver();
    Cursor cursor;
    cursor = cr.query(eventsUri, new String[]{ "_id" },"calendar_id=" + 1, null, null);
    while(cursor.moveToNext()) {
        long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
        cr.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
    }
    cursor.close();
    // Show message
    Toast.makeText(getApplicationContext(), "Calendar Cleared!",Toast.LENGTH_LONG).show();
    

    0 讨论(0)
提交回复
热议问题