Creating Calendar Events – Using WebView – in Android

Creating Calendar Events – Using WebView – in Android

Hey – it’s been a while.

No time like the present to write a post about Android coding.

Specifically: “how do I create a calendar event from within a WebView in Android?”

First, let’s talk game plan. I am going to construct an url “scheme” that will indicate to a handler that I want to create a calendar event, and not navigate to a web page; then, I need to call an Intent that will allow the event to be created.

Easy Peasy.

So, for my dates that I wish to portray on a web view, I do something like the following:

<a href='date:beginmonth, beginday, beginyear, 
endmonth, endday, endyear, My Event Description'>
My event link</a>

Then, I construct a shouldOverrideUrlLoading handler that will detect that a date: is being clicked, and handle it specially (see the code below):

final WebView crimeView = (WebView) findViewById(;

crimeView.setWebViewClient(new WebViewClient() {


public boolean shouldOverrideUrlLoading (WebView view, String url)


if (url.startsWith("date:")) {


Calendar beginCal = Calendar.getInstance();

Calendar endCal = Calendar.getInstance();

Date beginDate = new Date(0, 0, 0);

Date endDate = new Date(0, 0, 0);

String parsed = url.substring(5);

String[] components = parsed.split(",");









calendarevent(beginCal, endCal, components[6]);

return true;


return false;



Finally, we need code to invoke the Calendar intent. It looks like the following:

 // Create a calendar event
    public void calendarevent(Calendar begintime, Calendar endtime, 
                              String eventName) 
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.putExtra("beginTime", begintime.getTimeInMillis());
        intent.putExtra("allDay", false);
        intent.putExtra("rrule", "FREQ=YEARLY");
        intent.putExtra("endTime", endtime.getTimeInMillis()+60*60*1000);
        intent.putExtra("title", eventName);

And that, as they say, is that.

2 thoughts on “Creating Calendar Events – Using WebView – in Android

  1. Hi David, nice post about webview and calendar events, but I tried to apply your method to the app I’m developing and some of the code is said to be deprecated. Any chance you know a new way of doing so? Cause it seems no one knows how to do it anymore, android sdk has some dark sides there..
    Anyway, if you can help me with this I’d appreciate it so much!


  2. Thanks for sharing the useful example. I have question about including the start time and end time in the calendar event, what should I do?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s