Playing flash videos on android webview..

Was recently playing around with getting a youtube video to run on a webview in android. Was able to run it fine using the iframe but had issues getting some control over it. Same with ooyala videos.

Simple issues like video still playing once i leave the activity, on orientation change, etc..

It was rather simple in the end, coz webview exposes methods like onPause and onResume to provide control on the flash content being played in that webview.

Here are few things that you can do:

Handle your orientation. This would help keep the video running continuously even on orientation change. Modify your manifest like below.. and override onConfigurationChanged method to handle the orientation change.

<activity android:name:"MyActivity"




In your activity, handle onResume, onPause and onDestroy and control the webView instance from there. Create the webview as presented in the method showVideo. It basically loads the youtube video in an iframe. You can use the link of embeddable version of youtube video.



Hope it helps someone.. Let me know if there’s any better way.

When you can’t differentiate..

How do you differentiate one work from another? The real involvement lies there.

We generally come across many people who’re statistics driven.

people who look at numbers and make future predictions..

people who look at some random percentages and make judgement on other folks..

people who read numbers and assume they know the story.

Well, a Dravid’s century is a lot different from Sehwag’s century which is lot different from a Steven Waugh’s century. But statistically, they’re only centuries. You can’t differentiate based on that.

For people who know less (or care less), those figures and stats are all they need to know.

For people who care, or really interested in stuff, they go beyond numbers. Infact, numbers don’t matter to them at all. They can genuinely differentiate one stuff from another. Good from bad, bad from ugly, what’s the next line.. nevermind.

When you can’t differentiate one person from another, one company from another, one music from another, and need stats to help you make decision, well.. you’re basically ill-informed and paralyzed in some way. Go get more information. Talk to people. Learn about things.

When you can’t differentiate, don’t make decisions. Either learn about it, or leave it to professionals.


Save and Update with Sugar

This post helps demonstrate the ease with which you can save and update a record with the help of Sugar in android project.

For an introduction to Sugar, click here.

Firstly, to enable your model to utilize Sugar’s benefits, you need to have configured Sugar in the manifest file (as shared in the introduction) and the model needs to extend SugarRecord.

Saving a record becomes straight forward, as you’re only interacting with your objects and not the usually messy way of dealing with SQL queries directly. Here’s a way to save a record using Sugar:

// Note class represents model. It extends SugarRecord.
Note note = new Note(context);
note.setTitle("Make Tea");
note.setDescription("Add tea along with milk and sugar. Boil for few minutes");;

That is all you need to do to save a record into the android database. The save() method takes care of inserting the record into its corresponding table.
Similarly, modifying and updating a record is made very simple with Sugar. Here’s a way to do it.

// obtain a reference to the note record from database.
Note note = Note.findById(context, 1);
note.setDescription("Take some water. Add milk, tea and sugar. Boil it for few minutes");;

Here findById() is a query method to obtain the record with id 1 from the table. After getting the reference to the instance, modify the values and call the save() method to update the record into the table.

So, as you see, saving and updating records is made very straight forward with the use of Sugar. The code is located here  . Check out SugarExample for an example project.

Do try it out.

Sugar : Android database made easy.

UPDATE : Some of the code snippets in the below post are outdated. Please visit for latest updates to the library.

This post is an introduction to Sugar library for android. The aim of the project is to simplify database access in Android.

The project draws inspiration from GORM for grails or Active Record for Rails. These patterns have been hugely successful in the web world, and have set a benchmark for libraries for database access.

The basic objectives of the library  are:

1. Creation and management of database and connection.

2. Simple and Intuitive API for database querying.

3. Simple CRUD operations.

Source Code

Source code is present at

You can clone it and start hacking. There’s a build script along with it to compile and generate the binary.

An example project using the library is present at


Android Manifest file: 

Include the android:name attribute in the application tag. SugarApp extends android’s Application and initiates the database creation for the project. By including the attribute, you’re basically starting with SugarApp instead of android’s Application class. If you intend to write your own Application class, you can extend SugarApp.

<?xml version="1.0" encoding="utf-8"?>
<application.. android:name="com.orm.SugarApp">

The entities need to inherit from SugarRecord including a typed parameter. SugarRecord provides for all the CRUD methods that will be available to the entity classes.

public class Note extends SugarRecord<Note>{
private String title;
private String description;
public Note(Context context){

Thats about it. Configuration is done. You’re ready to dive into the sweetness of Sugar. (OK.. I couldn’t stop myself from saying this.)

# inserting values

Note note = new Note(context, "Note 1");;

# query

Note.findById(context, Note.class, 1);
Note.find(context, Note.class, "title=?", new String[]{"Note 1"});

# delete
Note note = Note.findById(context, Note.class, 1);

# few more..

Note.listAll(context, Note.class);
Note.deleteAll(context, Note.class);

Nice.. All done. Happy Android hacking.

You can’t hide the bitter truth..

Yes. Sooner or later, it would come out.

It leaves you two ways to combat it. One, the cowardly way.. look away from it, don’t share it with people, hide it, punish people for revealing it,  conceal it by any possible means.

Other way is to share it. Share it with all honesty. Show confidence in people.

The second approach gives you all control over the moment, the occasion you reveal the truth. The first one only manages to scare you and makes you repeat the same over and over.

In both cases, you’re unaware of the outcome. But in latter approach, you tend to control better.

‘Find the Blind’ renamed to ‘Find the Light’

Find the Blind, the project to help doctors and health workers detect and treat children at early stages of vision related defects, has been started and following are some updates on the progress of it..

1. A more positive outlook.

‘Find the Blind’ has been renamed to ‘Find the Light’.  There were many suggestions regarding the name ‘Find the Blind’ which sounded inappropriate and negative. Though it conveyed the context of the whole project, the communication carried a negative tone about it. Since the project is such a positive initiative, the name has to do the due justice to it. Hence came ‘Find the Light’. The name is self-explanatory and conveys the context beautifully as well.

2. Tremendous response on the introductory post

We received tremendous response on the introductory post, which is extremely encouraging. Couple of our dev folks have shown interest in contributing to the development of the software. Thanks for the encouragement, and we hope to see many more contributions in different forms during the course of the project. In continuation to this effort, we’ll try to keep posting update on the progress.

3. Progress on the software

Here are some screenshots of the app so far.. in a very nascent stage.

Note for contributors:

If you’d like to contribute in anyway possible to this, please write back to me at satya[at] stating the way you’d like to contribute.

We’re looking for contribution primarily in the following areas:


1. Developers on android/python/django platform.

2. Architects to help review the solution design.

Financial Sponsorship:

3. To procure hosting environment. We’ll probably go with EC2.

4. Android devices. One tablet with GPS and one/two smartphone.

Social Project Execution

5. We’d need some project co-ordinators to help with the social activity.

Find the Blind – Project.

Lately, I’ve been contributing to this project ‘Find the Blind’, developing a technical solution to one of its functions. This has been a part-time thing that I’ve been working on along with my friend Deepan Subramani (developer at Thoughtworks), who has decided to help in his spare hours. This project is very special to me personally, and I’m sure this could help improve, in its own little way, the way we use technology for improving healthcare in rural areas.

This article serves two purposes:

1. We’re announcing it publicly, so it pushes us to deliver  (since we’re all working part-time on this).

2. It is also an effort to attract like-minded people to come along and help us with the project. Contributions are required on all fronts, especially technically and financial sponsorship-wise.

So, here we go..

Find the Blind is a project undertaken by Dr. Ashwin Mallipatna to detect and treat visual defects in children at a very early stage, especially in rural areas. More about this effort here.

Visual defects not detected and treated at early stage can later lead to severe consequences, total vision loss being one of them. This affects the overall future of the country with many youngsters coming out with visual defects, that could have been treated. With this vast a population, it poses many challenges to detect these defects at an early stage. This project tries to solve this problem with a social strategy involving village panchayats and schools in the overall setup.

With the above introduction, I move on to the technical point. There are two areas which need some technical intervention.

One, with the detection of the defect itself. Medical instruments are very costly and mostly static (stay in one premise). Portable ones have low degree of accuracy and aren’t suitable for rough handling. To solve this, the team went with an innovative Red reflex screening method, where an inexpensive digital camera with the right parameters and subject conditions is used to take appropriate readings. This strategy was well received and was recognized as a technology innovation by MIT’s publication. You can read more about it here.

Second part is location part. Since rural areas aren’t well connected, it becomes difficult for a team to keep track of all patients identified and  schedule visits  for regular check-ups. It is essential to have a system that can help locate a patient’s house and also allows access to patient’s information for viewing and modifying.

This is where our technical solution comes into play. Here are few brief details regarding the solution:

It involves an android based smartphone/tablet, which the health-worker carries. Our application deployed to the device would help the health-worker to locate the patients by giving out directions to the patient’s address. It also acts as an offline data collection tool, which the health worker uses to gather health information about the patient. Later the patient’s health details gets uploaded to the central server. The back-end patient system is build with django/python and will be the central store for all the information. The data exchange between the android client and the django server is in json format.

The two of us, I and Deepan, have just started implementing the above mentioned solution and looking to finish in the coming month or two. We should be able to get it up and running by the end of July to beginning of August.The project will undergo a pilot till the end of this year in a village near Bangalore, and (after its success) will be launched for use in other parts of the state.

It is going to be an extensive effort on part of everyone involved, and we’ll try our best to pull it off the best way we could.

If you’d like to contribute in anyway possible to this, please write back to me at satya[at] stating the way you’d like to contribute.

Note for contributors:

We’re looking for contribution primarily in the following areas:


1. Developers on android/python/django platform.

2. Architects to help review the solution design.

Financial Sponsorship:

3. To procure hosting environment. We’ll probably go with EC2.

4. Android devices. One tablet with GPS and one/two smartphone.

Social Project Execution

5. We’d need some project co-ordinators to help with the social activity.