Thursday, January 14, 2010

How to deploy Android application?

1. Create icon for your application and add it to the project
 image
image
2. Export unsigned application
Right click on the project. Click on “Android Tools->Export Unsigned Application Package…”
image
2. Generate personal certificate by using keytool in java’s jre\bin directory
image
3. Sign Android application by using jarsigner in jre\bin direcotry
image
4. Installation
a) Install application on emulator
image 
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
image
b) Your Signing Certificate
image
2. Go to this link to sign up for an Android Maps API key
3. Add the key to your application’s AndroidManifest.xml
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
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”
image

Read, Write and Parse XML file in Android

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


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
parser.setInput(isr);
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:
break;
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));
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("category") &&
currentCategory != null){
categories.add(0, currentCategory);
} else if (name.equalsIgnoreCase("packingList")){
done = true;
}
break;
}
eventType = parser.next();
}
} catch (FileNotFoundException e) {
// TODO
} catch (IOException e) {
// TODO
} catch (Exception e){
// TODO
}


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 );
osw.flush();
osw.close();

} 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.
image
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
image
I went to “Help->Software Updates…” and installed the developer tools in below screen shot.
image

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)
image
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!”
 image
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 https://dl-ssl.google.com/android/eclipse/” 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.
image
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
image

Welcome to Android Ideas!

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