关于提醒日历的咨询

时间:2014-10-07 06:38:43

标签: android

我试图提醒我的日历活动。

这是我的活动代码。

for (long gg=1;gg<=4;gg++)
            {
                    long calID = gg;

                    long startMillis = 0; 
                    long endMillis = 0; 

                    Calendar cal = Calendar.getInstance();
                    MyDay = cal.get(Calendar.DAY_OF_MONTH);
                    MyMonth = cal.get(Calendar.MONTH);
                    MyYear = cal.get(Calendar.YEAR);

                    MyHoure = cal.get(Calendar.HOUR_OF_DAY);
                    MyMinute =cal.get(Calendar.MINUTE);

                    Calendar beginTime = Calendar.getInstance();
                    beginTime.set(MyYear,  MyMonth,  MyDay , MyHoure+1, MyMinute);
                    startMillis = beginTime.getTimeInMillis();
                    Calendar endTime = Calendar.getInstance();
                    endTime.set(MyYear,  MyMonth,  MyDay , MyHoure+1, MyMinute);
                    endMillis = endTime.getTimeInMillis();

                    ContentResolver cr = getContentResolver();
                    ContentValues values = new ContentValues();
                    values.put(Events.DTSTART, startMillis);
                    values.put(Events.DTEND, endMillis);
                    values.put(Events.TITLE, "Test Title");
                    values.put(Events.DESCRIPTION, "My Text ....."  );

                    values.put(Events.CALENDAR_ID, calID);
                    values.put(Events.EVENT_TIMEZONE, "Israel/tel-aviv");

                    try{
                    Uri uri = cr.insert(Events.CONTENT_URI, values);
                    }
                    catch (Exception ex)
                    {
                    }
            }

我需要添加到我的代码中,以便在活动开始前10分钟进行提醒?

我尝试这样的事情:

 Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");
         values = new ContentValues();
         values.put( "event_id", Long.parseLong(event.getLastPathSegment()));
         values.put( "method", 1 );
         values.put( "minutes", 10 );
         cr.insert( REMINDERS_URI, values );

但它不起作用。

感谢

1 个答案:

答案 0 :(得分:0)

我已经完成了您的代码,我相信这个谜题中缺少的部分是将hasAlarm值放在您的内容值中,默认情况下该值...

values.put(Events.HAS_ALARM, true);