My R&D World

All Things R&D

GSoC 2012 Weekly Report on OI WebIntents Agent (June 18-24)


Last week I was trying to integrate Android apps for web intent invocations. The task is much harder than I thought, and it is only half-done now. Here I would like to share a screen shot for the button click event at

Now at least two problems are in the way:

  1. How to map a Web intent to its corresponding Android intents
  2. How to transfer data of types other than ’text/*‘

I am afraid I may not solve the two perfectly at current stage but I will try every effort.

Next week I will continue with the remaining integration work. If it is done, I will start with developing the management interfaces of the intents registry.

I would appreciate very much if you have any feedback.



GSoC 2012 Weekly Report on OI WebIntents Agent (June 11-17)

Hi there,

In the last week, I solved the login issue of Twitter. It’s a problem of cookie management during HTTP transactions. I’ve written an article on how to make cookie set-get operations when making HTTP request-response by your self. The github code has been updated. It should be much better than the last version.

Another big change is that I created a CustomWebView class and overrode its loadUrl method instead of the previous shouldOverrideUrlLoading of the default WebView class. It’s my fault for past detours. I should have used this method earlier.

Another activity class named “org.openintents.wiagent.ui.WebIntentsAgentActivity” was created for naming reasons, it was to substitute for the work of WIAgentWebView which will be disposed of in the future. As for all the class changes which relate to the design part, I will update the design report before middle-term evaluation.

Some one told me the fire of “DOMContentLoaded” is much faster than “onload”. I spent one afternoon in testing their performance. For mobile devices, DOMContentLoaded is indeed faster than onload (around 60 seconds, so slow for onload). But it still be not enough for this project (I think it might be a result of the Webkit two pass layout for mobile versions, i.e. rendering first, others later). So I think the method of Javascript injection which I used in applying will be abandoned in this project.

I couldn’t make it to add local apps to the suggested application list last week. That continues to be on my schedule for this week.


Cookie Management in Android Web Apps Development

I write this article because cookie management was a big issue which I spent quite some time on it in my GSoC2012 project but Google provides little reference.

Google engineers suggested using HttpURLConnection which would be a trend instead of Apache HTTP Client in this blog. However, HttpURLConnection has far less APIs than Apache HTTP Client which makes new programmers a little confused on how to manage cookies during HTTP request-response transactions. Even the reference of HttpURLConnection provides little useful materials on this field but only suggest using vm-wide cookie manager.

Actually, android.webkit has a very useful cookie manager which makes our programming much easier. Its full name is “android.webkit.CookieManager”.

Below is the code script which I use for cookie management in HTTP request-response.

HttpURLConnection urlConnection = null;
try {
    urlConnection = (HttpURLConnection) url.openConnection();

    // Set cookies in requests
    CookieManager cookieManager = CookieManager.getInstance();
    String cookie = cookieManager.getCookie(urlConnection.getURL().toString());
    if (cookie != null) {
        urlConnection.setRequestProperty("Cookie", cookie);

    // Get cookies from responses and save into the cookie manager
    List cookieList = urlConnection.getHeaderFields().get("Set-Cookie");
    if (cookieList != null) {
        for (String cookieTemp : cookieList) {
            cookieManager.setCookie(urlConnection.getURL().toString(), cookieTemp);

    InputStream in = new BufferedInputStream (urlConnection.getInputStream());
} catch (IOException e) {
} finally {
    if (urlConnection != null) {

Line 6 returns a singleton CookieManager so you don’t have to worry about cookie lost when using it in different places. Line 14 is to get cookies if the response message has multiple “Set-Cookie” fields.

Cookies are critical in login system of many websites. Hope this article will help you.

GSoC 2012 Weekly Report on OI WebIntents Agent (June 3-10)

Hi there,

Eventually, I escaped the annoying and frustrating realm surrounded by GFW and made it to have access to Twitter and all the websites I need.

This week, I implemented the simple share activity, though still with some bugs. The app starts with a local html file including links online. When you click the link, it will redirect you to the onlne “startActivity” page from The reason for this is that I need to change the page code before it is loaded into the WebView.  The button of the page will start an “” activity. Then our agent  will suggest you with related registered apps, Twitter now.

The function is now very simple and buggy. The main cause is the limited api of android.webkit. It seems sometimes “shouldOverrideUrlLoading” does not get called as I want. I think I should discuss with others on this problem.

Next step, I plan to let the suggested apps having local Android apps on the list which is one of the goals of this project.

The latest code has been published. Because of my skills, I believe they are not very good. Any feedbacks are welcome.


GSoC 2012 Weekly Report on OI WebIntents Agent (May 22-June 2)


Sorry for the currently slow development.

Since my blog at is blocked by GFW, I have submit this week’s report here. Next week I will go back to Canada and everything will be back to normal.

The current published version of the agent runs far less reliable on intent invocation grab of some examples at, especially for those in iframes. The reason is because a bug from Javascript same orgin policy being created after the website had been updated.

My former idea was to insert Javascript code before WebView loading corresponding pages which let the Java code on Android grab intent invocations. I was trying to insert the code in the method “onPagefinished” of WebViewClient. But after many tests, I found the solution is unreliable. Because the connection speed of mobile devices is far less than a desktop computer, the moment when this method get called is slow and uncertain. The user may often have to wait several minutes for my inserted scripts to execute. This problem also happens to the “onload” event.

Now I am overriding the method “shouldOverrideUrlLoading” of WebViewClient by getting Http response in my own code, modifying the data and loading it into WebView. The initial development goes smoothly and I have succeed in grabbing the intents invocation at

A problem is when “shouldOverrideUrlLoading” gets called. I’ve tested some conditions and it only didn’t get called when loading url in “onCreate” method of Activity. I can work around this as long as the first shown page of the app not containing any intents invocation.

In the next week, I will focus on this new solution to get it working on web twitter.

GSoC 2012 Pre-coding Report (May 7-21)

Cheers for the beginning of coding period of GSoC.

Since I am now in China with limited Internet access (I didn’t expect so many web sites are
blocked by GFW), the present development is significantly affected.
The current status of OI WebIntents Agent is as follows:
1. I’ve changed the design of UI, replacing the previous control buttons with
action items in the action bar which makes the look and feel better.
2. I added a menu item named ‘Registered applications’, though very simple now,
where the user can do some management executions on his registered
applications. Twitter is a prepopulated application now for future test.

Parsing and executing js scripts by WebView of Android seems to be very slow
and buggy. So grabbing web intents related js function execution by Java does
not work always good and I am thinking about better solutions to fix it.

I’ve uploaded the project onto GitHub at’ so that anyone can make
suggestions on my coding. Any feedbacks are welcome.

It is difficult for me to publish this report because is on the
blacklist of GFW. I think my next report will also come in two weeks,
immediately after I come back to Canada.

GSoC 2012 Pre-coding Report (April 30-May 6)

Hi there,

The second bonding week for GSoC 2012. This week openintents moved its code repositories onto Github.

To be consistent I had a plan on changing the name of my project to “OI WebIntents Agent” and using “org.openintents.wiagent” as the package name of the promising app. Another big plan is that I was thinking about using a content provider instead of former pure SQLite database access because I found it has more benefits for future maintenance including test and update.

Here I would like to share a similar work from phonegap.

The work I did last week:

  • Create a WebIntentsProvider. The work is just half-done.
  • Populate the WebIntentsProvider with the SHARE intent.
  • Reading the source code of other projects from openintents to be familiar with its code style.
  • Cleaning up the demo code used for application. The work is almost done.
  • Bonding period work of GSoC and openintents.

The next report will come in two weeks. That is the last pre-coding report before the coding work formally starts. I hope I can make a very initial demo at the moment.


GSoC 2012 Pre-coding Report (April 23-29)

Hi there,

I am so happy that my proposal for GSoC 2012 is finally accepted. This is my first trip on GSoC so the acceptance have me gain a lot of confidence.

This project is to implement a Web Intents user agent on Android which works as a bridge between Web Intents and the Android intents. We are all familiar with the Android intents. So what is Web Intents?

Web Intents is a framework for client-side service discovery and inter-application communication.

It comes from the Android intents system and works on the Web. Like the Android intents, a Web intent also encapsulates attributes such as action, data type, extras but it still adds some other attributes to make it operational in the Web world. As a result of the commonality of the two mechanism, it may be possible to build a connection between them.

To my knowledge, the biggest feature of Web Intents is substituting decentralized service discovery for the used-to-be centralized service discovery mechanisms like UDDI. This is an exploratory project and the Web Intents specification is still ongoing. So a lot of challenges are waiting for me. However, I believe it will be a promising filed and it is greatly rewarding to do this project.

The mentor organization of this project is Since I am still new to this community, I still have a lot of materials to learn. Very happy to have a chance to work with its members.

What I did in the last week:

  • Familiar with Drupal which is the CMS of
  • Organizing the project code to remove nonsense parts and what was for feasibility test
  • GSoC 2012 bonding period work

What I am going to do this week:

  • Writing an initial version of Web Intents registry on Android-embeded SQLite
  • Populating the registry with some existing Web Intents applications’ information like Twitter
  • Continue to clean up my code
  • GSoC 2012 bonding period work

Thanks for your attention.