删除在Android日历提供事件 [英] delete events from Calendar Provider on Android

查看:716
本文介绍了删除在Android日历提供事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用Calendar提供用于添加,编辑和删除事件的应用。我有一个日历,这说明这几天有要事连接的接口。添加事件完美的作品。对于添加事件我很难codeD的calendarID与3号,这样的calid = 3。

I have an application which uses the Calendar Provider for adding, editing and removing events. I have an interface of a calendar, which shows which days have events attached. Adding events works Perfectly. For adding an event I hardcoded the calendarID with the number 3, so calID = 3.

long calID=3;
values.put(Events.DESCRIPTION, description);
    values.put(Events.CALENDAR_ID, calID);
    values.put(Events.EVENT_TIMEZONE, "Europe/London");
    Uri uri = cr.insert(Events.CONTENT_URI, values);

这完美的作品。查看我已经设定显示的事件。我打开它来包括在我的手机(的Xperia J)的日历应用程序,我可以看到该事件的存在。

This works perfectly. the View i've programmed shows the events. I open the Calendar application which comes included on my phone (Xperia J) and I can see that the event is there.

我试图删除具有以下code事件:

I tried to delete events with the following code:

        ContentResolver cr = mContext.getContentResolver();
    ContentValues values = new ContentValues();
    Uri deleteUri = null;
    deleteUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
    int rows = mContext.getContentResolver().delete(deleteUri, null, null);

这code是直接从developer.android.com网站复制。 这不会删除!我调试的code和的行的值等于1,所以effectivelly行应已被删除。 不过,我回到我的应用程序,而该事件仍然存在那里。有趣的事情:我已经签了进来我的手机日历应用程序,而该事件不存在那里。因此,它已被删除(?)。我想,也许我不会刷新我的应用程序,所以我关闭了它,重新安装它,它永远不会删除。我再次调试code删除,并再次行值等于一体,非常相同的事件!因此,行总是返回1,每次我想要的删除。因此,该行已被删除,但并未被删除。

This code was DIRECTLY copied from developer.android.com website. This doesn't Delete! I debugged the code and the value of 'rows' is equal to 1, so effectivelly the row should have been deleted. However I get back to my app, and the event still exists there. Interesting thing: I've checked the Calendar Application that comes in my phone, and the event doesn't exist there. So it has been deleted (?). I thought that maybe i am not refreshing my app, so i closed it, reinstalled it, and it never deletes. I debug again the code for deletion, and once again the 'rows' value is equal to one, to the very same event! So, 'rows' is always returning 1 EVERY TIME i want to the delete it. So the row was deleted, but it was not deleted.

这是怎么回事?是不是因为当我加入的情况下,我很难codeD的calendarID?

What is happening here? Is it because when I added the event, I hardcoded the calendarID?

推荐答案

正如您所注意到,删除一个事件并没有真正从数据库中删除行,直到事件被同步到服务器。 这是很合乎逻辑的,否则日历同步适配器将无法检索事件数据发送一个DELETE请求到服务器。这就是为什么出现在事件表中删除的列,您的必须的检查查询事件时:

As you noticed, deleting an event doesn't really remove the row from the DB until the event is synced to the server. It's quite logical, otherwise the calendar sync adapter would not be able to retrieve event data to send a DELETE request to the server. That's why there is a DELETED column in the event table, which you must check when querying events:

<一个href="http://developer.android.com/reference/android/provider/CalendarContract.SyncColumns.html#DELETED" rel="nofollow">http://developer.android.com/reference/android/provider/CalendarContract.SyncColumns.html#DELETED

顺便说一句,如果你查询实例,而不是事件(这确实扩大经常性的事件),删除事件从结果中自动删除。

By the way if you query Instances instead of Events (which does expansion of recurring events), deleted events are removed automatically from the result.

这篇关于删除在Android日历提供事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆