我正在尝试将项目放入日历中,但无法真正找到如何对其进行编码。这是我目前所拥有的,但它将它插入到主日历中。
String calName;
String calId = null;
String[] projection = new String[] { "_id", "name" };
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = managedQuery(calendars, projection, null, null, null);
ContentValues event = new ContentValues();
event.put("calendar_id", calId);
event.put("title", strTitle);
event.put("description", strDescription);
event.put("eventLocation", strLocation);
event.put("dtstart", StartTime);
event.put("dtend", EndTime);
Uri eventsUri = Uri.parse("content://calendar/events");
Uri calUri = getContentResolver().insert(eventsUri, event);
所以我的问题是:
如何创建自己的日历以将 Activity 放入
如何将我的 Activity 插入该日历(使用上面的代码或新代码)
如何检查事件是否已经存在
~~~更新:~~~
我想做的是我的用户将输入标题和日期,我的应用程序将采用该标题和日期,将它们放入数据库(到目前为止我所做的一切),现在我想获取标题和日期并将它们放入专门用于我的应用程序事件的特殊日历中。我需要做的第一件事是让应用程序创建一个新日历。比将事件插入到日历中,下面的代码可以帮助我做一些事情。还在玩它。比我想重新运行我的应用程序并检查事件是否存在。就这些。
最佳答案
首先,自 2.2 以来内容解析器发生了变化,我认为从 content://calendar/calendars
到 content://com.android.calendar/calendars
。
要插入 Event ,检索 Event 检查此代码
您将找到所需的一切以及如何跨平台处理内容解析器更改。
关于安卓日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6318507/