android谷歌补丁日期,在谷歌日历Android中添加开始日期和结束日期之间所有日期的事件...

在谷歌日历

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);

}

此功能每天都会添加事件.如何删除.我只需要rest.Is我的代码有什么问题吗?

412057157d6da6bcc3cb879afd6e8d05.pngRoeB0.jpg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值