My R&D World

All Things R&D

Category Archives: Android

User Guidelines for OI WebIntents

Hi there,

This blog presents a summary of user interface for current OI WebIntents. Now the app supports both tablets and handsets.

This is the main page with an introduction section, a service registration section, a service invocation section and a link to home page of

There are five action items in the action bar: backward, forward, reload, goHome and applicaiton management.

When a new application is found, a notification message is shown. The user can enter into application management interface by click on the notification or the menu item.

There are three tabs in the Web application management interface: New Found, My App and Trash, each with its own menu items. The sign “+” here means add the checked Web apps in New Found tab to My App, while “-” means removing them to trash. Since in current version, the agent no longer marked visited applications and ignore them in future visits, I put a trash tab here for recycling instead of deleting unused applications forever.

When entering the simple share web page on and click on the share button, a chooser dialog appears (with or without web apps).

Now you can use Web application like Twitter or Android application like Gmail to complete your action.

When running the share sample app now, the chooser dialog appears in its own context now.

The interface for handsets is similar.

The biggest difference is displaying Web applications and their web intents. Still, in the intents detail interface, a user can make same menu operations as its parent. Since back button shows different results from in tablets, I added a navigation up support for the application icon to return to the home page.


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.