开发者

Add reminder to calendar

Hi I am currently using the following code to add an event to the android's default calendar.

Calendar cal = Calendar.getInstance();              
Intent intent = new Intent(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", "A Test Event from android app");
intent.putExtra("description", "Who knows! this might work");
intent.putExtra("eventLocation", "Hope this time it works");
intent.putExtra("hasAlarm", 1);
startActivity(intent);

My question is, will it be possible to edit this code so that I can add reminder to the calendar?


There are some posts in the forums here about how this can be achieved. There are multiple ways, including using some APIs found in google code, but I found what seems to be a simpler method, even though I have not tried it before and I am not sure but suspect that the warning it triggers is based in the default. But with some exploration you should be able to find a way to customize it.

In any case, as mentioned in here: how to edit the calendar events via android application

You should use a ContentValues object, which works as a calendar entry

ContentValues event = new ContentValues();

For this object, you can activate an alarm in this way:

event.put("hasAlarm", 1); // 0 for false, 1 for true

The post does not refer how to set the alarm settings, but you might be able to find those by investigating into which string keys you can use for the put method when using ContentValues for a Calendar intent.

Once you are done, you can put the event into the calendar in this way:

Uri eventsUri = Uri.parse("content://calendar/events");
Uri url = getContentResolver().insert(eventsUri, event);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜