首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在日历中添加提醒

如何在日历中添加提醒
EN

Stack Overflow用户
提问于 2012-03-25 18:30:08
回答 1查看 1.2K关注 0票数 1

嗨,我正在android上实现生日提醒应用程序。请告诉我在日历上设置提醒的步骤是什么。我已经在安卓里拿到日历了。

EN

回答 1

Stack Overflow用户

发布于 2012-03-25 19:06:55

您可以使用它在Android日历中添加事件。

代码语言:javascript
复制
GregorianCalendar startDate = new GregorianCalendar(Locale.ENGLISH);
            startDate = CustomDateFormatter.formatScheduleDate(schedule.getScheduleStartDate());

            GregorianCalendar endDate = new GregorianCalendar(Locale.ENGLISH);
            endDate = CustomDateFormatter.formatScheduleDate(schedule.getScheduleEndDate());

            try{

                String[] projection = new String[] { "_id", "name" };
                Uri calendars = Uri.parse("content://com.android.calendar/calendars");
                Cursor managedCursor = mContext.getContentResolver().query(calendars, projection, "selected=1", null, null);
                ContentValues event = new ContentValues();

                long StartTime = startDate.getTimeInMillis();
                long EndTime = endDate.getTimeInMillis();
//              int nameColumn = managedCursor.getColumnIndex("name"); 
                int idColumn = managedCursor.getColumnIndex("_id");

                if(managedCursor.moveToFirst()){

//                  String calName = managedCursor.getString(nameColumn);
                    String calId = managedCursor.getString(idColumn);

//                  Log.e("Cal name", calName);

                    event.put("calendar_id", calId);
                    event.put("title", schedule.getScheduleType());
                    event.put("description", schedule.getScheduleTextContent());
                    event.put("dtstart", StartTime );
                    event.put("dtend", EndTime);
                    event.put("hasAlarm", 1);

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

                    Uri remindersUri = Uri.parse("content://com.android.calendar/reminders");
                    event = new ContentValues();
                    event.put("event_id", Long.parseLong(calUri.getLastPathSegment()));
//                  Log.d("Event ID: ", calUri.getLastPathSegment());

                    event.put("method",1);
                    event.put("minutes",0);

                    mContext.getContentResolver().insert(remindersUri, event);
                }

                managedCursor.close();

            }catch(Exception ex){
                ex.printStackTrace();
            }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9859462

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档