从我的应用程序的日历中输入数据-在生日而不是事件或提醒中输入 [英] Data Entry in Calender from my application - Entry in birthday instead of events or reminder

查看:73
本文介绍了从我的应用程序的日历中输入数据-在生日而不是事件或提醒中输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于第一个if条件(routineObject.getSchedule()== 1),数据进入日历事件,但对于其他条件,它进入生日而非事件。我希望所有人都参与活动或提醒。

For the first if condition (routineObject.getSchedule()==1) data goes into events of calender but for other condition it goes into birthdays instead of events. I want all of them into events or reminders.

任何解决方案??

    String eventUriString = "content://com.android.calendar/events";
    ContentResolver cr = this.getContentResolver();
    ContentValues values = new ContentValues();

    if (routineObject.getSchedule() == 1) {

        dateTimeString = dateString + " " + SelectedTime;
        Date dateDateTime;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH : mm");

        try {
            dateDateTime = sdf.parse(dateTimeString);
        } catch (ParseException e) {
            e.printStackTrace();
            dateDateTime = new Date();
        }
        long millisecondsTimesNew = dateDateTime.getTime();

        values.put(CalendarContract.Reminders.CALENDAR_ID, routineObject.getId());
        values.put(CalendarContract.Reminders.TITLE, "Routineer");
        values.put(CalendarContract.Reminders.DTSTART, millisecondsTimesNew);
        values.put(CalendarContract.Reminders.DESCRIPTION, todoTextOneTIme);
        values.put(CalendarContract.Reminders.DTEND, millisecondsTimesNew);
        values.put(CalendarContract.Reminders.HAS_ALARM, true);
        values.put(CalendarContract.Reminders.EVENT_TIMEZONE, TimeZone.getDefault().getID());


    } else if (routineObject.getSchedule() == 2) {

        Date mDate;
        SimpleDateFormat sdfdate = new SimpleDateFormat("yyyy-MM-dd");
        try {
            mDate = sdfdate.parse(endDate);

        } catch (ParseException e) {
            e.printStackTrace();
            mDate = new Date();
        }
        long EndtimeInMilliseconds = mDate.getTime();

        dateTimeStringEveryday = startDate + " " + SelectedTime;
        Date dateDateTimeEveryday;
        SimpleDateFormat sdfEveryday = new SimpleDateFormat("yyyy-MM-dd HH : mm");

        try {
            dateDateTimeEveryday = sdfEveryday.parse(dateTimeStringEveryday);
        } catch (ParseException e) {
            e.printStackTrace();
            dateDateTimeEveryday = new Date();
        }
        long millisecondsStartTimesEveryday = dateDateTimeEveryday.getTime();

        values.put(CalendarContract.Reminders.CALENDAR_ID, routineObject.getId());
        values.put(CalendarContract.Reminders.TITLE, "Routine Everyday");
        values.put(CalendarContract.Reminders.DTSTART, millisecondsStartTimesEveryday);
        values.put(CalendarContract.Reminders.HAS_ALARM, true);
        values.put(CalendarContract.Reminders.RRULE, "FREQ=DAILY"); //UNTIL=1924885800000
        values.put(CalendarContract.Reminders.DTEND,EndtimeInMilliseconds);
        values.put(CalendarContract.Reminders.DESCRIPTION, todoTextEveryDay);
        values.put(CalendarContract.Reminders.EVENT_TIMEZONE, TimeZone.getDefault().getID());
    }



    Uri eventUriOneTime = this.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), values);
    eventID = Long.parseLong(eventUriOneTime.getLastPathSegment());
    alertSelection();


推荐答案

我们代码中的主要罪魁祸首是:

The Main Culprit in ur code is:

values.put(CalendarContract.Reminders.CALENDAR_ID, routineObject.getId());

在您的情况下设置常规对象的ID时出现问题

There is a problem while setting the Id of the routine Object in ur case

Some devices uses calendar id = 1 for birthdays but generally not. 

这是我们将事件推送到生日日历中的原因,U可能已经设置了常规对象为1,但是您创建Java对象时。

That is the reason ur events are being pushed into Birthday Calendar,U might have been setting the Id of the routine Objects as 1,While u create The Java Objects.

请为您不希望生日的常规对象设置适当的Id不等于1事件。

Please set the appropriate Id not equal to 1 for the Routine Objects which u intend not to get into birthdays instead of events.

这篇关于从我的应用程序的日历中输入数据-在生日而不是事件或提醒中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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