This is my blog where I hope to post information about what I am doing technically and what my family is up to. I hope you enjoy

Tuesday, June 22, 2010

Displaying SQLite Data from Android Application

As I was building my Android application that uses an SQLite database I needed to determine what the actual data in the tables were due to the fact I had a bug in my application.   I need a tool like sqlplus, toad or PLSQL that enables one to peer into the tables.       I thought I could do this using the DDM perspective in the Eclipse Android plugin but this does not enable one to do so or rather I could not find a way to do this.

So here where the steps that I took to peer into my SQLite database tables.

First you need to get access to the SQLite database file where the information is stored.   Since I am building using Eclipse I Pull the file via the DDMS view within Eclipse.  The image below shows how this can be done within the Eclipse IDE.



After selecting on your database, in my case TASKS_DATABASE, you then select the Pull File you need to save it on your file system.   Pull File will grab the file from your emulater and place it onto you file system directory.

Once saved you need a tool that will help you peer inside this data.  I found a nice tool called SQLite Database Browser to do this exact task.    After unzipping the downloaded file.  Launch the database browser and Open the SQLite database file you just downloaded.   Here is a screen shot of the SQLite utility before loading the file I just pulled from Eclipse DDM view.


This shows three database tables within my SQLite database.  Choose the one you want to view and select on Browse Data.  This will display the contents of the data as shown below.



Use this tool to peer inside your data like you would with Oracle PL/SQL or Toad tools into Oracle.

Now I did this for the database that resides on the Emulator.   I believe you cannot do this to a database that reside on a real Android OS phone due to security reasons.  Or at least I hope not.


There is also another way to view what is in your SQLite tables via the adb shell and querying the database from the shell.

First need to get into the adb shell and cd to the directory where your applications database resides.
In this example I cd  data/data.

Now you need to cd to the application directory.
You will see the TASK_DATABASE file.  To get into the database you now execute the following.
>sqlite3 TASKS_DATABASE   shown below.

You can execute SQL to see what is in the tables.

Wednesday, June 9, 2010

Google Maps Key

To get a Google Maps API key one has to first create an MD5 certificate fingerprint using the keytool from Java SDK.

Here is how I created that certificate using the keystore tool included in the JDK.
keystore -genkey -v -keystore delaney_keys.keystore -alias delaney_keys

You will go through a series of questions such as: name, city, password, etc
At the end of all the questions your keystore in my case delaney_keys.keystore will be created.

Now to get the MD5 key you execute the following command.

keystore -list -alias  delaney_keys  -keystore delaney_keys.keystore
You will be prompted for your password you entered above and once entered successfully the MD5 Certificate will be printed on the command line.

Using this to obtain your Google API Key
Go the Google API Registration page

Accept the terms on the agreement and enter the MD5 certificate that the keytool printed out above.  After entering the MD5 and submitting the page you will be displayed with a valid Google Maps API key that you can then use within your Android application to call the Google Maps API.
Layout-->Edit HTML -->