7

GoogleカレンダーAndroidで開始日と終了日の間のすべての日のイベントを追加. 終了日まで3か月ごとに残りが必要です。これが私の機能です

    public void addEvent1(Context ctx, String title){
            SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy");
            SimpleDateFormat df3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.getDefault());
            Date Startdate = null;
            Date Enddate =null;
            String dtStart = date.getText().toString();
            try {
                Startdate = df2.parse(dtStart);
                Enddate = df2.parse(stringMaturityDate);
                Log.v("SDate: ",""+ df3.format(Startdate));
                Log.v("EDate: ",""+ df3.format(Enddate));
            } catch(ParseException e){
                e.printStackTrace();
            }
            Calendar cali = Calendar.getInstance();
            cali.setTime(Startdate);


            Calendar cali2 = Calendar.getInstance();
            cali2.setTime(Enddate);

            SimpleDateFormat yyyymmdd = new SimpleDateFormat("yyyyMMdd");
            Calendar dt = Calendar.getInstance();


            dt.setTime(Enddate);

            String dtUntill = yyyymmdd.format(dt.getTime());

            ContentResolver contentResolver = ctx.getContentResolver();

            ContentValues calEvent = new ContentValues();
            calEvent.put(CalendarContract.Events.CALENDAR_ID, 1); // XXX pick)
            calEvent.put(CalendarContract.Events.TITLE, title);
            calEvent.put(CalendarContract.Events.RRULE, "FREQ=MONTHLY;INTERVAL=3;UNTIL=" + dtUntill);
            calEvent.put(CalendarContract.Events.DTSTART, cali.getTimeInMillis());
            calEvent.put(CalendarContract.Events.DTEND, cali2.getTimeInMillis());

            calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "" + java.util.Locale.getDefault());



            Uri uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI, calEvent);


                int id = Integer.parseInt(uri.getLastPathSegment());
               Toast.makeText(ctx, "Created Calendar Event " + id,
                       Toast.LENGTH_SHORT).show();
 ContentValues reminders = new ContentValues();
        reminders.put(CalendarContract.Reminders.EVENT_ID, id);
        reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
        reminders.put(CalendarContract.Reminders.MINUTES, 10);

        Uri uri1 = contentResolver.insert(CalendarContract.Reminders.CONTENT_URI, reminders);
        }

この関数は毎日イベントを追加します。それを取り除く方法。残りだけが必要です。コードに何か問題がありますか?? スクリーンショット1スクリーンショット2

4

1 に答える 1

4

私がすべてを正しく読んだ場合、丸 1 日で 3 か月ごとにカレンダー アイテムが必要になります。この行を追加しようとしましたか?

contentValues.put(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

また、1 つのカレンダー アイテムの終了日が現在年末に設定されているのに対し、これは現在のアイテムの終了日である必要があります。DTEND は現在の項目の終わりです。DURATION は繰り返しパターンの終わりです。

問題を間違って理解した場合は、詳細な説明をお願いします。CalenderContracts のすべてのオプションについては、このリンクを確認してください。

編集:

毎日のカレンダーの予定が必要ですが、3 か月ごとにユーザーに通知します。あなたのコードでは、そのIDを持つすべてのカレンダーアイテムにリマインダーを追加しているため(毎日)、これは現在不可能です。私が考えることができる唯一の簡単な解決策は、リマインダーと別の ID を使用して 3 か月ごとに繰り返す別の ID で別の予定を作成することです。現在、同じ ID を持つイベントとそうでないイベントにアラームを設定することはできません。

于 2016-05-17T12:10:44.103 に答える