Android-使用事件创建自定义日历 [英] Android - Create Custom Calendar with Event

查看:116
本文介绍了Android-使用事件创建自定义日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示特殊日子的应用程序。我想将它们集成到日历中。

I have an App which shows special Days. I want to integrate them into the calendar.

事件是静态的,它们不会更改,因此我不必经常更新日历。

The events are static, they don't change, so I don't have to update the calendar very often.

我首先想到创建本地日历并添加事件,但是新的android版本(自2.3开始)似乎不支持该功能;要实现,我必须创建一个日历提供程序。

I first thought of creating a local calendar and add the events, but new android versions (since 2.3?) seem not to support that; to implement I would have to create a Calendar Provider.

我在github上看到了这个项目: https://github.com/dschuermann/birthday-adapter 。这非常复杂;它的主要用途是将联系人的生日添加到新日历中。

I saw this project on github: https://github.com/dschuermann/birthday-adapter. It is very complicated; its main use is adding the birthdays of the contacts to a new calendar.

有很多代码,其中很多我都不需要。我真的需要注册到android的客户经理来集成Calendar Provider吗?我只需要一个带有活动的新日历...

There is lots of code, much of which I don't think I need. Do I really need to register to android's account manager to integrate a Calendar Provider? I just need a new Calendar with my event...

使用用户的默认日历并在其中添加所有活动会更容易吗?我可以在描述中添加一些标识符,以便在用户不希望出现的事件时将其删除。

Would it be easier to take the user's default Calendar and add all the Events there? I could add some identifiers to the description, to be able to remove the events if the user doesn't want them.

任何提示,教程或其他阅读材料都将受到赞赏。

Any tips, tutorials, or further readings are appreciated.

Metin Kale

Metin Kale

推荐答案

您可以在设备中创建事件通过Intent进行日历。我认为这可能对您有用。

You can create events in your device calendar via Intent. I think it could be useful for you.

public long addEventToCalender(ContentResolver cr, String title, String addInfo, String place, int status,
                                      long startDate, boolean isRemind,long endDate) {
    String eventUriStr = "content://com.android.calendar/events";
    ContentValues event = new ContentValues();
    // id, We need to choose from our mobile for primary its 1
    event.put("calendar_id", 1);
    event.put("title", title);
    event.put("description", addInfo);
    event.put("eventLocation", place);
    event.put("eventTimezone", "UTC/GMT +2:00");

    // For next 1hr
    event.put("dtstart", startDate);
    event.put("dtend", endDate);
    //If it is bithday alarm or such kind (which should remind me for whole day) 0 for false, 1 for true
    // values.put("allDay", 1);
    //  event.put("eventStatus", status);
    event.put("hasAlarm", 1);

    Uri eventUri = cr.insert(Uri.parse(eventUriStr), event);
    long eventID = Long.parseLong(eventUri.getLastPathSegment());

    if (isRemind) {
        String reminderUriString = "content://com.android.calendar/reminders";
        ContentValues reminderValues = new ContentValues();
        reminderValues.put("event_id", eventID);
        // Default value of the system. Minutes is a integer
        reminderValues.put("minutes", 5);
        // Alert Methods: Default(0), Alert(1), Email(2), SMS(3)
        reminderValues.put("method", 1);
        cr.insert(Uri.parse(reminderUriString), reminderValues); //Uri reminderUri =
    }
    return eventID;
}

有关更多信息,请访问 http://developer.android.com/reference/java/util/Calendar.html

For more information visit http://developer.android.com/reference/java/util/Calendar.html

这篇关于Android-使用事件创建自定义日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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