Thursday, January 14, 2010

How to deploy Android application?

1. Create icon for your application and add it to the project
2. Export unsigned application
Right click on the project. Click on “Android Tools->Export Unsigned Application Package…”
2. Generate personal certificate by using keytool in java’s jre\bin directory
3. Sign Android application by using jarsigner in jre\bin direcotry
4. Installation
a) Install application on emulator
b) Install application on device
I downloaded ASTRO File Manager and copied the apk file to device. Use File Manager to find the file and tap on it. It prompted me a couple of questions. I have to change my device setting to allow unknown source apps to be installed on my device.

How to obtain Google Map Key for Android Application?

This link will give detailed information on how to get Google Map Key for Android Application. I don’t need to repeat it. Here I just want to give simplified steps for future reference:
1. Get MD5 Fingerprint of the Certificate
a) SDK Debug Certificate
b) Your Signing Certificate
2. Go to this link to sign up for an Android Maps API key
3. Add the key to your application’s AndroidManifest.xml
android:apiKey="[your key]"

MapActivity cannot be resolved to a type

When I first working on with MapActivity, I got above error. I kept press Ctrl+Shift+O. However, the type just wouldn’t resolve. Finally I found the answer on the Internet. You need to change the build target to “Google API”
Right click on the project. Go to “Properties”. Change the “Build Target” from “Android 1.x to Google APIs 1.x”

Read, Write and Parse XML file in Android

1. Read and Parse Xml file
The sample XML file looks like the following:
<category name="test">

The following code shows you how to read and parse the file
ArrayList<Category> categories;
XmlPullParser parser = Xml.newPullParser();
try {
FileInputStream fIn = openFileInput(FILE_NAME);
InputStreamReader isr = new InputStreamReader(fIn);

// auto-detect the encoding from the stream
int eventType = parser.getEventType();
Category currentCategory = null;
boolean done = false;
while (eventType != XmlPullParser.END_DOCUMENT && !done){
String name = null;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("packingList")){
categories = new ArrayList<Category>();
} else if (categories != null){
if (name.equalsIgnoreCase("category"))
currentCategory = new Category(parser.getAttributeValue(0));
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("category") &&
currentCategory != null){
categories.add(0, currentCategory);
} else if (name.equalsIgnoreCase("packingList")){
done = true;
eventType =;
} catch (FileNotFoundException e) {
} catch (IOException e) {
} catch (Exception e){

2. Write to file
try {
FileOutputStream fOut = openFileOutput(FILE_NAME, MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
String fileContent = …; //build file content
osw.write(fileContent );

} catch (FileNotFoundException e) {



Tuesday, January 12, 2010

How to kill an application running in Android Emulator?

Since I am not a Java programmer, there is a learning curve using Eclipse. I am getting used it. But sometimes I have to search the Internet to find answers for really simple question like this one. And here is how.
1. Click on “DDMS”
2. Select the application you want to kill
3. Click on “Stop”

Android 2.0 Update

To get Android SDK 2.0 update, go to “Windows->Android SDK Manager” to download the new update.
After download the update, I got the following message when try to open my existing application
I went to “Help->Software Updates…” and installed the developer tools in below screen shot.

Issues with running my first “Hello Android” application

Soon after I have the environment setup, I created my first Android application “Hello Android”. The app is sure simple, but I still run into some issues when running it.
The first one is “HelloAndroidConversion to Delvik format failed with error 1” (see screen shot below)
I am not a Java programmer and I have no idea what the issue is. After searching the answer on the Internet, I found the solution. That is go to “Project-Clean…” in Eclipse.
Then I received error “Could not find HelloAndroid.apk!”
It turned out to be the path I added to the system variable. I added “C:\Android\GlassFish-Tools-Bundle-For-Eclipse-1.1\jre\bin” to Path in windows system environment variable. I removed “\bin” and do “Project->Clean…” again. The issue is gone.
The emulator kept shutting down even after I passed these two issues. I had to start the emulator first. Even so, it failed to run it the first time. But it worked the second time and after. Strange!

Thursday, January 7, 2010

Android Development Environment Setup

1. Download Android SDK 1.6
2. Download GlassFish tool bundle for Eclipse 1.1
Don’t ask me why GlassFish. That is the first Eclipse tool I found, so I just installed it.
3. Install Android plug-in in Eclipse
If you got the “No repository found at” error when using the URL on Andorid web site which is the checked one in the following screen shot, use the second URL on the screen instead.
4. Install AVD(Android Virtual Device)
\[Android sdk folder]\tools\android create avd –-target 2 –-name my_avd
Don’t forget to add “[Eclipse folder]\jre” to the PATH in Environment Variables
5. Set up Android SDK location in Eclipse. Go to Windows->Preferences

Welcome to Android Ideas!

This is the place I want to share my experience on learning Android programming. Let's start.