Android创建日历事件始终为生日 [英] Android Create Calendar Event always as Birthday

查看:107
本文介绍了Android创建日历事件始终为生日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我以编程方式创建日历事件时,我遇到了一个奇怪的问题 它总是被标注为生日日历(类型),我不知道为什么它被这样标注.

I have a strange issue when i create a calendar event programmatically its always noted as Birthday Calendar (type) i don't have any clue why its noted like that.

我使用的代码如下:Xamarin C#

My code i use is as below: Xamarin C#

ContentResolver cr = ((Activity)Forms.Context).ContentResolver;
ContentValues values = new ContentValues();
String eventUriString = "content://com.android.calendar/events";

//Insert Events in the calendar...
values.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 1);
values.Put(CalendarContract.Events.InterfaceConsts.Title, title);
values.Put(CalendarContract.Events.InterfaceConsts.Status, 1);
values.Put(CalendarContract.Events.InterfaceConsts.Description, description);
values.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(year, month, day, hour, minute));
values.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(year, month, day, hour, minute));
values.Put(CalendarContract.Events.InterfaceConsts.AllDay, allday ? "1" : "0");
values.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, hasalarm ? "1" : "0");
values.Put(CalendarContract.Events.InterfaceConsts.EventColor, Android.Graphics.Color.Green);
values.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "GMT+" + zone + ":00");
values.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "GMT+" + zone + ":00");
cr.Insert(Android.Net.Uri.Parse(eventUriString), values);

请问有人有什么提示或想法可以指引我正确的方向吗?

Please does someone has any tips or ideas wich can point me to the right direction ?

谢谢.

推荐答案

下面回答的问题很旧,请参考 Pkosta的提供更准确答案的答案...

The question answered below is old please refer to Pkosta's answer which provides more accurate answer ...

您必须将CalendarId值设置为3而不是1,这是默认的生日日历. 例如

You have to put CalendarId value as 3 instead of 1 which is default birthday calendar. e.g.

 values.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 1);

将其更改为

values.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 3);

它为我解决了同样的问题.

It solved the same issue for me.

这篇关于Android创建日历事件始终为生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆