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.

Transparent Backgrounds on Android Views

Transparent Backgrounds on Android Views

A frequent question encountered when using WebView inside of an Android app is “how do I make the background transparent, rather than the default white color?

This is ridiculously easy:

WebView myWebView = new WebView(this);

Happy Coding.