首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >嵌入日历事件和提醒

嵌入日历事件和提醒
EN

Stack Overflow用户
提问于 2018-05-28 16:34:50
回答 1查看 288关注 0票数 0

我想通过我的android应用程序(Android studio)在google calender中添加提醒,但我已经尝试了所有方法,但它没有添加到日历中。我也尝试过通过https://developer.android.com/guide/topics/providers/calendar-provider#events添加,但仍然没有成功。

代码语言:javascript
复制
            Date d1 = new Date(1472570400);//Tue, 30 Aug 2016 15:20:00 GMT
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(d1);

        Date d2 = new Date(1472574000);//Tue, 30 Aug 2016 16:20:00 GMT
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(d2);

        Uri EVENTS_URI = Uri.parse("content://com.android.calendar/events");
        ContentResolver cr = getContentResolver();

        // event insert
        ContentValues values = new ContentValues();
        values.put("calendar_id", 1);
        values.put("title", "Reminder Title");
        values.put("allDay", 0);
        values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());                

        values.put("dtstart", cal1.getTimeInMillis() ); // event starts at Tue, 30 Aug 2016 15:20:00
        values.put("dtend", cal2.getTimeInMillis()); // ends at Tue, 30 Aug 2016 16:20:00 GMT

        System.out.println("ALARM TIMES START : " + cal1.getTimeInMillis());
        System.out.println("ALARM TIMES END : "+cal2.getTimeInMillis());

        values.put("description", "Reminder description");                
        values.put("hasAlarm", 1);
        Uri event = cr.insert(EVENTS_URI, values);

        // reminder insert                
        Uri REMINDERS_URI = Uri.parse("content://com.android.calendar/reminders");
        values = new ContentValues();
        values.put( "event_id", Long.parseLong(event.getLastPathSegment()));               

        values.put( "method", 1);
        values.put( "minutes", 1); //Notify before the exact time
        cr.insert( REMINDERS_URI, values );
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50562224

复制
相关文章

相似问题

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