我正在学习如何使用Android日历.到目前为止,我能够显示有关现有日历的信息.我也可以创建自己的本地日历 – 测试代码如下:
private void createCalendarTest()
{
Uri.Builder builder = Calendars.CONTENT_URI.buildUpon();
builder.appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true")
.appendQueryParameter(Calendars.ACCOUNT_NAME,"private")
.appendQueryParameter(Calendars.ACCOUNT_TYPE,CalendarContract.ACCOUNT_TYPE_LOCAL);
Uri uri = builder.build();
ContentValues values = new ContentValues();
values.put(Calendars.NAME,"TEST");
values.put(Calendars.CALENDAR_DISPLAY_NAME,"Calendar named TEST");
values.put(Calendars.SYNC_EVENTS,false);
values.put(Calendars.VISIBLE,true);
getContentResolver().insert(uri,values);
}
实际上,我可以创建许多仅在_ID中有所不同的日历.我在别处读过,我只能在使用同步适配器时创建日历.现在,我该如何删除日历?我希望URI还必须包含同步适配器信息和已删除日历的_ID.我尝试了以下代码,但我没有成功:
private void deleteCalendarTest()
{
Uri.Builder builder = Calendars.CONTENT_URI.buildUpon();
builder.appendPath("6") // here for testing; I know the calender has this ID
.appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,CalendarContract.ACCOUNT_TYPE_LOCAL);
Uri uri = builder.build();
getContentResolver().delete(uri,null,null);
Toast.makeText(this,"??? deleteCalendarTest() not working",Toast.LENGTH_SHORT).show();
}
我该如何解决?
最佳答案