【问题标题】:Android CalendarView issueAndroid CalendarView 问题
【发布时间】:2017-05-02 12:25:36
【问题描述】:

在我使用 CalendarView 的 android studio 项目中,我想在一天按钮上显示事件。那么如何突出显示日期按钮,以便用户知道特定日期包含事件?

预期输出:-

【问题讨论】:

    标签: java android oop calendar


    【解决方案1】:

    在您的代码中使用此 API.. 它将帮助您插入事件,可以启用带有提醒的事件和带有会议的事件...此 api 适用于平台 2.1 及更高版本那些使用低于 2.1 而不是内容的人: //com.android.calendar/events 使用内容://calendar/events

    public static long pushAppointmentsToCalender(Activity curActivity, String title, String addInfo, String place, int status, long startDate, boolean needReminder, boolean needMailService) {
    /***************** Event: note(without alert) *******************/
    
    String eventUriString = "content://com.android.calendar/events";
    ContentValues eventValues = new ContentValues();
    
    eventValues.put("calendar_id", 1); // id, We need to choose from
                                        // our mobile for primary
                                        // its 1
    eventValues.put("title", title);
    eventValues.put("description", addInfo);
    eventValues.put("eventLocation", place);
    
    long endDate = startDate + 1000 * 60 * 60; // For next 1hr
    
    eventValues.put("dtstart", startDate);
    eventValues.put("dtend", endDate);
    
    // values.put("allDay", 1); //If it is bithday alarm or such
    // kind (which should remind me for whole day) 0 for false, 1
    // for true
    eventValues.put("eventStatus", status); // This information is
    // sufficient for most
    // entries tentative (0),
    // confirmed (1) or canceled
    // (2):
    eventValues.put("eventTimezone", "UTC/GMT +2:00");
    

    /*在可见性和透明度列下方注释以避免java.lang.IllegalArgumentException列可见性无效错误*/

    /*eventValues.put("visibility", 3); // visibility to default (0),
                                        // confidential (1), private
                                        // (2), or public (3):
    eventValues.put("transparency", 0); // You can control whether
                                        // an event consumes time
                                        // opaque (0) or transparent
                                        // (1).
      */
    eventValues.put("hasAlarm", 1); // 0 for false, 1 for true
    
    Uri eventUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues);
    long eventID = Long.parseLong(eventUri.getLastPathSegment());
    
    if (needReminder) {
        /***************** Event: Reminder(with alert) Adding reminder to event *******************/
    
        String reminderUriString = "content://com.android.calendar/reminders";
    
        ContentValues reminderValues = new ContentValues();
    
        reminderValues.put("event_id", eventID);
        reminderValues.put("minutes", 5); // Default value of the
                                            // system. Minutes is a
                                            // integer
        reminderValues.put("method", 1); // Alert Methods: Default(0),
                                            // Alert(1), Email(2),
                                            // SMS(3)
    
        Uri reminderUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
    }
    
    /***************** Event: Meeting(without alert) Adding Attendies to the meeting *******************/
    
    if (needMailService) {
        String attendeuesesUriString = "content://com.android.calendar/attendees";
    
        /********
         * To add multiple attendees need to insert ContentValues multiple
         * times
         ***********/
        ContentValues attendeesValues = new ContentValues();
    
        attendeesValues.put("event_id", eventID);
        attendeesValues.put("attendeeName", "xxxxx"); // Attendees name
        attendeesValues.put("attendeeEmail", "yyyy@gmail.com");// Attendee
                                                                            // E
                                                                            // mail
                                                                            // id
        attendeesValues.put("attendeeRelationship", 0); // Relationship_Attendee(1),
                                                        // Relationship_None(0),
                                                        // Organizer(2),
                                                        // Performer(3),
                                                        // Speaker(4)
        attendeesValues.put("attendeeType", 0); // None(0), Optional(1),
                                                // Required(2), Resource(3)
        attendeesValues.put("attendeeStatus", 0); // NOne(0), Accepted(1),
                                                    // Decline(2),
                                                    // Invited(3),
                                                    // Tentative(4)
    
        Uri attendeuesesUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(attendeuesesUriString), attendeesValues);
    }
    
    return eventID;
    

    }

    希望对你有帮助

    有关更多信息,您可以参考以下链接 How to add calendar events in Android?

    【讨论】:

    • 您能否详细说明此代码。我无法使用这个。 @Abdul Waheed
    猜你喜欢
    • 2018-07-08
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-26
    相关资源
    最近更新 更多