android 日历 events 无法保存,CalendarContract.Events.CALENDAR_ID不使用Intent将事件存储在Android中指定的Calendar_Id中(Cal...

Hi I am using the following Code to add a Event to my Android Calendar using Intent.

Calendar cal = Calendar.getInstance();

Intent intent = new Intent(Intent.ACTION_INSERT); // Even Tried Intent.ACTION_EDIT

intent.setType("vnd.android.cursor.item/event");

intent.putExtra("beginTime", cal.getTimeInMillis());

intent.putExtra("allDay", false);

intent.putExtra("rrule", "FREQ=DAILY");

intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);

intent.putExtra("title", mtodoText);

intent.putExtra(CalendarContract.Events.CALENDAR_ID,3);

startActivity(intent);

But the issue is that this event is not saved or Created to the Calendar_Id = 3, but inspite that it is created to the calendar_Id = 1. I am using the following code to retrieve all of my Calendar Events, And if I check the log cat output it shows the event is created in Calendar_Id 1.

Uri EVENTS_URI = Uri.parse(getCalendarUriBase(true) + "events");

String sSelection = "((" + CalendarContract.Events.DELETED + " != 1))";

/*String sSelection = "((" + CalendarContract.Events.CALENDAR_ID + " = 3 ) AND ("

+ CalendarContract.Events.DELETED + " != 1))";*/

cur = getActivity().getContentResolver().query(EVENTS_URI, null, sSelection, null, "_id");

if(cur!=null){

while (cur.moveToNext()) {

String taskname=cur.getString(cur.getColumnIndex(CalendarContract.Events.TITLE));

String taskdate=cur.getString(cur.getColumnIndex(CalendarContract.Events.DTSTART));

String s_id=cur.getString(cur.getColumnIndex(CalendarContract.Events._ID));

String taskstatusflag=cur.getString(cur.getColumnIndex(CalendarContract.Events.HAS_ALARM));

Log.e("Title:", "taskname: " + taskname);

Log.e("DTSTART","taskdate: " + taskdate);

Log.e("_ID","s_Id: "+ s_id);

Log.e("HAS ALARM", "taskstatusflag: " + taskstatusflag);

Log.e("Calender ID:",cur.getString(cur.getColumnIndex(CalendarContract.Events.CALENDAR_ID))+"");

}

}

My Logcat Out is as Follows:-

05-31 17:17:54.039 6518-6518/com.myapp E/Title:﹕ taskname: test1

05-31 17:17:54.039 6518-6518/com.myapp E/DTSTART﹕ taskdate: 1464608459000

05-31 17:17:54.039 6518-6518/com.myapp E/_ID﹕ s_Id: 22162

05-31 17:17:54.039 6518-6518/com.myapp E/HAS ALARM﹕ taskstatusflag: 0

05-31 17:17:54.039 6518-6518/com.myapp E/Calender ID:﹕ 1

05-31 17:17:54.039 6518-6518/com.myapp E/Title:﹕ taskname: test Cal 3

05-31 17:17:54.039 6518-6518/com.myapp E/DTSTART﹕ taskdate: 1464684678000

05-31 17:17:54.039 6518-6518/com.myapp E/_ID﹕ s_Id: 22163

05-31 17:17:54.039 6518-6518/com.myapp E/HAS ALARM﹕ taskstatusflag: 0

05-31 17:17:54.039 6518-6518/com.myapp E/Calender ID:﹕ 1

05-31 17:17:54.039 6518-6518/com.myapp E/Title:﹕ taskname: test guest

05-31 17:17:54.039 6518-6518/com.myapp E/DTSTART﹕ taskdate: 1464694253000

05-31 17:17:54.039 6518-6518/com.myapp E/_ID﹕ s_Id: 22164

05-31 17:17:54.039 6518-6518/com.myapp E/HAS ALARM﹕ taskstatusflag: 0

05-31 17:17:54.039 6518-6518/com.myapp E/Calender ID:﹕ 1

05-31 17:17:54.039 6518-6518/com.myapp E/Title:﹕ taskname: test Cal 3

05-31 17:17:54.039 6518-6518/com.myapp E/DTSTART﹕ taskdate: 1464694676000

05-31 17:17:54.039 6518-6518/com.myapp E/_ID﹕ s_Id: 22165

05-31 17:17:54.039 6518-6518/com.myapp E/HAS ALARM﹕ taskstatusflag: 0

05-31 17:17:54.039 6518-6518/com.myapp E/Calender ID:﹕ 1

05-31 17:17:54.039 6518-6518/com.myapp E/Title:﹕ taskname: test Cal 33

05-31 17:17:54.039 6518-6518/com.myapp E/DTSTART﹕ taskdate: 1464695268000

05-31 17:17:54.039 6518-6518/com.myapp E/_ID﹕ s_Id: 22166

05-31 17:17:54.039 6518-6518/com.myapp E/HAS ALARM﹕ taskstatusflag: 0

05-31 17:17:54.039 6518-6518/com.myapp E/Calender ID:﹕ 1

What should I do to explicitly create the event in Calendar_Id = 3, Using the Intent.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值