Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Android 2.2中添加日历和事件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想要的:我想在 Android 2.2中添加日历事件.

我有什么:我使用以下代码添加一个事件

Uri calendars = Uri.parse("content://com.android.calendar/events");
    cursor managedcursor = managedQuery(calendars,null,null);

    startManagingcursor(managedcursor);
    managedcursor.moveToFirst();

    String ID = null;

    do
    {
        ID = managedcursor.getString(managedcursor.getcolumnIndexOrThrow("_id"));
    } 
    while (managedcursor.moveToNext());
    managedcursor.close();      

    int newID = Integer.parseInt(ID) + 1;

    ContentValues event = new ContentValues();
    event.put("calendar_id",NewID);  // --- Some confusion Here with the ID,// --- not sure how to use it here
    event.put("title","New Event title");
    event.put("description","Event Desc");
    event.put("eventLOCATIOn","Somewhere");

    long startTime = System.currentTimeMillis() + 1000 * 60 * 60;
    long endTime = System.currentTimeMillis() + 1000 * 60 * 60 * 2;

    event.put("dtstart",startTimE);
    event.put("dtend",endTimE);

    event.put("allDay",0); // 0 for false,1 for true
    event.put("eventStatus",1);
    event.put("visibility",0);
    event.put("transparency",0);
    event.put("hasAlarm",1 for true

    Uri eventsUri = Uri.parse("content://com.android.calendar/events");
    Uri insertedUri = getContentResolver().insert(eventsUri,event);

问题是什么:
到目前为止,我已成功在指定的日期时间添加单个事件,显然NewID的角色对我来说是可疑的.当我尝试添加其他一些事件时,我得到返回的Uri insertedUri,它会在URI的末尾显示添加的ID.但我无法在设备上看到任何此类事件.可能是我对日历和事件的理解存在一些问题,或者两者及其ID的差异.请指导我错过或做错了什么.

问候,
Khawar

解决方法

大多数代码都很好,你只需要了解一些关于日历的概念.实际上Android中有多种日历类型.

要遍历所有日历,请使用以下Uri for 2.2:

Uri calendars = Uri.parse("content://com.android.calendar"+ "/calendars");

获得’id’和’name’的值,你就会得到这个想法.

NewID's role is suspicIoUs to me

您的插入代码很好,您只需要提供要插入任何事件的日历的ID.

我仍然相信即使我自己也需要学习很多,所以如果你有什么要说或纠正的话,我们非常欢迎你.以下链接帮助我:

Working with Android Calendars

Accessing Calendars events without using gdata api

大佬总结

以上是大佬教程为你收集整理的在Android 2.2中添加日历和事件全部内容,希望文章能够帮你解决在Android 2.2中添加日历和事件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。