Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不使用intent的情况下向android日历添加事件和提醒_Android_Calendar - Fatal编程技术网

如何在不使用intent的情况下向android日历添加事件和提醒

如何在不使用intent的情况下向android日历添加事件和提醒,android,calendar,Android,Calendar,我已经尝试了很多来自堆栈溢出的代码,但我能够添加事件和提醒。我是android开发的新手。请帮帮我 下面是找到的用于堆栈溢出的代码 ContentValues cv = new ContentValues(); ContentResolver cr = getContentResolver(); Calendar cal = Calendar.getInstance(); cv.put("calendar_id", 1); cv.put("ti

我已经尝试了很多来自堆栈溢出的代码,但我能够添加事件和提醒。我是android开发的新手。请帮帮我

下面是找到的用于堆栈溢出的代码

ContentValues cv = new ContentValues();
     ContentResolver cr = getContentResolver();
     Calendar cal = Calendar.getInstance();
        cv.put("calendar_id", 1);
        cv.put("title", "Prog");
        cv.put("dtstart", cal.getTimeInMillis() );
        cv.put("hasAlarm", 1);
        cv.put("dtend", cal.getTimeInMillis()+1000*60*60);
        cv.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());

        Uri newEvent ;

        if (Integer.parseInt(Build.VERSION.SDK) >= 8 ){
            newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
        }   
        else{
            newEvent = cr.insert(Uri.parse("content://calendar/events"), cv);
        }   

        if (newEvent != null)
        {
            long id = Long.parseLong( newEvent.getLastPathSegment() );
            ContentValues values = new ContentValues();
            values.put( "event_id", id );
            values.put( "method", 1 );
            values.put( "minutes", 0 ); // 15 minut Before
            values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
            if (Integer.parseInt(Build.VERSION.SDK) >= 8 )
                cr.insert( Uri.parse( "content://com.android.calendar/reminders" ), values );
            else
                cr.insert( Uri.parse( "content://calendar/reminders" ), values );
        }