Sketchbook app for Android

I have a Samsung Galaxy Note II. As you may already know, it has a big screen and the fact that it comes with a note taking app made by Samsung (I think) makes it very useful to jot down ideas, doodle, etc. I, however, wondered if there was an app that would facilitate doodling even more – a Photoshop caliber doodling app, if you will. Thus, began my search for a graphic program.

I tried the Sketchbook Express app and fell in love with it. It’s a bit limiting but you get an idea of what the paid version can do. I like the way the UI works, too. It doesn’t have any menus or anything visible on the screen – just a dot at the bottom. You tap the dot and out pop all tools. It has all sorts of brushes, color picker, the eye-dropper, etc. You can make a custom brush if preset ones don’t meet your needs.

After fiddling with the free version, I decided to get the paid version of the app (which was for $2.13 with taxes when I bought it). I am not an artist but after messing with the free and paid versions, I was able to draw these images.

This picture took me 2-3 hours on the free version:


I started making this one in the free version and completed it in the paid version (took me 3 weeks to complete – a few minutes here, a few minutes there):


Just to be safe: No one is allowed to use these images without my written permission.

Setting up your Android environment

I have seen quite a few posts on some lists asking about how to set up a programming environment for Android. While it is very straight forward, the documentation is all over the place. So, I decided to write this tutorial :).

In this tutorial, we will install Android SDK in eclipse (Galileo), we will add an SD Card to your emulator and put some pictures in it. I have written this tutorial with Windows users in mind but the process should not be very different for other platforms.

I have written this tutorial assuming that you already have JDK installed. If you don’t have it already installed then please install it before reading this. You can find a tutorial on how to install here.

Installing the SDK

  1. Download the latest eclipse IDE from

    You can also download Galileo directly from here.

  2. Create a folder in your c:\ drive and name it android. The file you just downloaded (at least from the direct link I provided above) is a zip file which contains a folder called eclipse. Extract the zip file and place the folder in, c:\android. Now, you have eclipse installed in c:\android. Go into the eclipse folder. You will see an executable called eclipse. Double click it to run eclipse.

    Click to enlarge
    Click to enlarge
  3. Now, download the android SDK 1.6 (the latest as of this writing) for windows from the link below: download the SDK for other platforms, go here :
  4. Extract the contents of the zip file in c:\android\. Now, you will have 2 folders in c:\android\. One is eclipse and the other is folder contains another folder called tools. We need to add this folder to the system’s PATH variable. To do that, Click on Start, then right click on “My Computer” and click on “Properties” in the menu that pops up.

The “System Properties” dialog will pop up. Click on the “Advanced” tab and then click on “Environment variables”. Another dialog will appear.

Run eclipse. Click on Help -> Install New Software.

Click to enlarge
Click to enlarge

An install dialog will appear. Click on “Add”, another dialog will appear. Type in Android for name and put in for Location. Then click OK. Click on next, check both the checkboxes and click next. Eclipse will start downloading the plugin and install it. You will be asked to restart eclipse after the installation is done. Click on “Yes” when it asks you to restart. Eclipse will restart and you can, now, create Android projects!

Click to enlarge
Click to enlarge

Now that the basic installation is done. Let’s setup the SC Card.

Setting up the SD Card

Creating the SD card is very easy.

  1. Click on Start -> Run. The run dialog will appear
  2. Type “cmd” (without the quotes) and hit enter or click the OK button. A commant prompt window will appear.
  3. Type “android list targets” in it and hit enter. It will show you a list of targets. Get the id for Android 1.6. It will most probably be 2
  4. Type the command “android create avd -n testavd -t <target_id> -c 128M” (without the quotes) and hit enter. Make sure to subsitute the <target_id> with the actual ID you got from “android list targets” command. Since it will most probably be 2, the command will look like this “android create avd -n testavd -t 2 -c 128M (again without quotes).
  5. Press enter 1 more time

Viola! you have created your SD Card for the emulator. The next time you start the emulator, you will be able to access it. Below is an illustration to make things easy.

Click to enlarge
Click to enlarge

When I created my SD card, I needed to get some pictures on it. So, I used an external program called winimage to do that.

Working with your SD card

  1. Download winimage from You can either get the zip file or the exe file. I downloaded the zip file, extracted it and use that.
  2. Run winimage.exe and make sure your emulator is not running.
  3. Click on Open image icon. Browse to c:\android\sd_card\ folder. Select sdcard and click OK button. Winimage will open the sdcard image. Now, you can browse the file structure and add files, delete files, etc. After you are done, make sure to close winimage or you won’t be able to access the SD card from the emulator.

As always here’s an illustration:

Click to enlarge
Click to enlarge

Now, we have an the SD Card image open. Let’s create a folder called “media” and put some pictures in it. When you take pictures with your phone’s camera they are stored in the media folder in  your SD Card.

To create the media folder, click on Image, then on Create Folder. A dialog box will appear. Type “MEDIA” in it. and Click OK. After the folder is created, you can drag and drop pictures from your computer to the media folder just like you would normally do it when copying files from one location on your computer to another.

Click to Enlarge
Create Folder
Click to enlarge
Copy pictures
Click to enlarge

Android HttpRequest class (version 2.1)

Version of of this class had some bugs so I corrected them and here is the latest version 🙂


You will also need the class below:

G2 on the way?

According to some rumors on IT news websites, some new Android phones will be released in 2009. claims that a phone, G2, is in the making and will be released in January of 2009. Another website claims that it will be released in April. Best of all, G2 will not be locked down to T-Mobile. It will be great to have a phone not locked down to T-mobile but this begs the question : WIll this phone be able to access T-mobile’s 3G services? And if yes, will it also be able to access 3G service of providers from the rest of the world who don’t use 1700 Mhz for 3G? I guess we will soon find out. 

An Australian company had announced the release of an Android based phone called Kogan Agora. It looks something like Samsung Blackjack and has no touch screen (as far as I can tell). A chinese firm, Lenovo, has also announced an Android based phone which will have touch screen but no physical keyboard. It looks something like HTC Touch HD from the front. The phone is called QIGI.

Looks like 2009 has some great things in store for all the phone lovers out there. Happy New Year everyone !

Working with a database in Android

Android uses SQLite for its database needs. SQLite is a very fast and lightweight database. It is file based which makes it highly portable and an ideal candidate for use as an embedded database. For those who prefer to just go through the code and learn, the Notebook application example on Android’s website can be very useful. Let’s begin with the tutorial shall we.

First, you will need to make a class that will interact with the database. After that class has been written, you will instantiate it and use it to perform your data operations. This will keep your code encapsulated and easy to maintain. Android tries to encourage its programmers to use the MVC concept and makes it easy to implement it.

Assume your table structure is this :

create tblData (
_id int primary key autoincrement,
alert_text text,

alert_date varchar(20),
alert_time varhcar(20)

Setting up Connections and getting everything ready

Our database interaction class will be called DBLayer. It is a public class, so it will need to be in a file called Let’s say we have a table with 3 fields and we want to set and get data from it. This is how you set the class up :

I have read articles which state a different way using databases in Android. From what I can tell these tutorials were for versions prior to 1.0. In version 1.0, you create a class which extends SQLiteOpenHelper and you encase that class in another class which you will call to insert and retrieve data. The comments in the code above should be self-explanatory. If you have any questions I haven’t answered, please leave a comment and I will post a reply.

You don’t need to have a database already set up. If the database you try to open doesn’t exist, then Android will create it. It will run the onCreate() method when it creates the database. And, if the database version changes on the phone. It will run the onUpgrade() method.

Running your Queries

Now the class DBLayer can connect to the database. However, just connecting is of no use unless you can retrieve some data from your database. There are 4 methods you can use in Android and they all perform different functions. They are : query, insert, delete and update. query() is used to retrieve data. The others should be self-explanatory.

Here’s a method that will retrieve multiple rows from the database:

You will rarely (if ever) find yourself writing any SQL for Android applications. The reason being Android’s framework does all the dirty work behind the scenes. All you have to do is set  your object up and provide the data retrieval, insertion methods with the neccesary information.

Here are some more methods. Everything should be self explanatory.

You can get the code for the whole class here. In this article, there wasn’t much explanation because I didn’t think I needed to explain anymore after pasting the code. I am sure there are people reading this who feel otherwise. Please let me know what needs more explanation and I will elaborate on that topic.

Debugging errors in Android

Android has a great framework to work in. However, it is in its infancy and debugging my code has been a very big problem for me. Whenever something goes wrong in the code, I always get “source not found” error. It doesn’t tell me I have a nullPointer exception , or string is incomplete.  No matter what’s wrong with the code, I always get “source not found” error. The reason that happens is Android doesn’t pack the source along with the application it sends to the emulator (maybe they should do that for a debugging run). After searching the net for a while, I came across this solution – wrap your code in a try and catch block and then log the exception to console. Here is an example :

Doing that will display a neat little line in your logcat window (look at the screenshots at the bottom). And, instead of getting the annoying “source not found” error. You will know what the actual error is. In Android, you can log three types of events – information, warning and error. Information is just verbose text being written out to the log.  I don’t need to explain warning and errors.

For logging information you can use :

Log.i(TAG, message);

For logging warnings you can use :

Log.w(TAG, message);

I have already shown how to log errors in the code above.

Click to enlarge
Click to enlarge
Click to enlarge
Click to enlarge

Programming for the beast named Android

Click for original size
Click for original size

I was messing around with Android’s development kit and I have to say, learning to develop an application for Android was much easier than trying to do it for Windows Mobile. I guess proper documentation helps – a lot. Google has put published tutorials on how to do some common tasks needed for making applications, and has  code reference documentation, etcetera which makes it easier to jump into it.

I am a very big fan of MVC and code and design separation in general. I was happy to find out that Android’s API lets you design the user interface in XML and then use that in your program. You can also do the design programmatically but who wants to do that (unless maybe you were adding / removing elements dynamically).

Google also provided an emulator to debug your software. It would have been a nightmare debugging my application without it. Beware of the “source not found” error. Whenever something goes wrong in your application, the debugger tries to reference the source of the place of error. And, the compiler doesn’t include source in the binary from what I understand. So, you get the debugger throws the error “Can’t find source”. There are workarounds for that problem posted on the internet, though.

When I started learning how to program for Windows Mobile (I have a Kaiser so I wanted to an FTP editor for it to edit HTML/PHP/whatever on the go). It took me quite some time to realize that you HAVE to buy Visual Studio if you want to program for it. It took me about a week to get started with Windows Mobile development but it took me a day for Android. And, the studio costs hundreds of dollars so that was out of the question for a hobby. Android, on the other hand, is free so I can use it with no cost at all. Don’t get me wrong. I am not putting Microsoft down. I am a programmer too and I know better than to say all software should be free. People need to make money and without an incentive there won’t be any good software. Visual Studio has great features which make programming very easy. I love their UI designer. I just want to have the choice to be able to program with their SDK without having to shell out 500+ dollars. Maybe if they let me use the SDK for free and asked to be paid for the visual studio, it would be a beter deal.

Anyway, after I got interested in the Android’s SDK, I decided to write some useful applications for it. I’m sure there will be enough users of Tmobile’s G1 phone who will want to use my application *fingers crossed*. Maybe I will make another post of what I plan to make that application do (hint: it will use geo-location service, run in the background and have a UI for settings and such).


Android’s home page :

Resources for developers :

Tutorials on various android related things :