Thursday, October 30, 2008

Manic 8-Ball

Funny story. I decided to be Manic 8-ball for Halloween.

The crafty part of the costume making wasn't working out, attaching a real magic 8-ball to the top. So, I thought. Hey, Why not write a program. I'll just attach the phone to my costume. It will be more like the real character :-)

Well, 2 hours later, here's the app. And, I will be submitting the code for others to enjoy. It's a really simple app.

Manic 8-Ball Project Site

Tuesday, October 28, 2008

Golan

Got a new Android phone? Do you like to read news and blogs but find yourself offline a lot away from wifi? On a plane? On a train? Maybe you don't like how awkward it is to browse on a phone? If you answered yes to any of these things (Android phone required) then maybe you should try out my little baby. The name is Golan. The name was inspired from Golan Trevize, a fictional character from Isaac Asimov's Foundation Series.

Applications like these have been around for some time. For years, I owned Palm devices and was a heavy Plucker user. When I lived in NY, I was often out of network range in the subway. Plucker was so useful. I don't know if anyone will port Plucker directly to Android. But, this is my start in that direction. Only 1 level of "plucking" so far, but I'm pleased with it for now. There is room for lots of improvement.

The project site is hosted on Google's Code site where you can download the source (soon to be committed) or a built version and install on your phone. Once I save up $30 for the registration fee, I will post it to the Android Market. And, it will be free.

Golan Project Home




Let's get plucking!

Wednesday, October 22, 2008

Installing your Android Application to your Phone Locally

I bought my G1 phone today. Yes, my Android phone. Dude. Am I happy. It is soo much faster than the emulator. So much fun. Not much time to play with it yet.

When I got it home tonight, I got to the task of getting my application installed on it.

Obviously the way to go is to just publish the application to one of the many marketplaces.

But, my app isn't ready yet. I want to install it on my phone and play with it and to get feedback from friends.

Here are the steps to getting that app on your phone. Maybe I will clean this up later.

Use keytool. From the command line (you obviously need the JDK installed):



Now you have a key. We will be using a self-signed key. Don't worry. Android accepts that.

Now you need to sign your .apk file. Screw the command line. You're gonna be doing this a lot. Use ant. Ant has a core task called oddly enough signjar.
Here's a build file you can start with.



Run the build. Hopefully, the "build" succeeds. Check the last modfied date on your file. It should have updated. It if it did, your jar should be signed. I'm sure there's a more intelligent way of examining it.

Now you can install your app on your phone. How the heck do you do that? Well, you need a server. Just install Tomcat locally. Copy the file to a simple web app. Modify your web.xml file (or your web server) to treat the .apk file extension as "application/vnd.android.package-archive".



Now add a link to your file in a web page or JSP. Hopefully the PC/laptop you're running this little local app is on your local network. And, you've turned on wi-fi on your phone. Go to your browser on your phone. Access your pc/laptop: http://192.168.1.10/yourapp/yourfile.jsp or some such url). Click the apk file and the Chrome browser should download the file. Once the file finishes click on the file. It should try to install the application. If it fails, it will tell you so. Unfortunately, it doesn't tell you why it failed. If it succeeeds, it will tell you and allow you to launch it.

Good luck!

Tuesday, October 7, 2008

Classpath Doh!

I keep learning more and more about building complex systems and the importance of getting classpath correct.

The other day I did an SVN update on my project. All of the sudden, this one piece of code wouldn't compile. I think it's probably OK to show this 1 line of code.



Anyway, the bit that was barking at me was javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI.
I asked a colleague where this lives. In rt.jar, he says. Waa? OK. It's in the JDK. I looked around in rt.jar. Yep. It's there. Why the hell isn't it compiling then?

Hmm. Here's the answer.

Project | Properties | Java Build Path | Order and Export
There was a jar in our project (which wasn't being used any longer) called jsr173_1.0_api.jar. That jar contains a class in the javax.xml package called XMLConstants just like in RT.jar. Only this copy did not have javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI. But, why does that affect whether it compiles or not? The jar without the class was listed higher in the classpath order. We didn't notice the problem before the JDK was previoulsy higher in the classpath order. Someone had re-ordered it on the last commit. Ugh. But, I'm glad they did it.

It was an easy fix for us. We were able to simply remove the unused jar from our project and the problem was gone. But, what if we couldn't remove it? Hmm. You can cheat, at least in the IDE. Though I'm sure that might have caused deployment issues. You can re-order the classpath by moving a class up or down in the list. Just click the jar in question and move it below the JDK entry. Voila, it compiles.

Be careful out there. It's a weird classpath world.

Friday, October 3, 2008

Android and sqlite3

Wow. For my new application which will go unnamed at the moment, I learned something very cool.

In the Eclipse Android SDK for Eclipse, there is a Perspective called DDMS. While your emulator (and application) is running, this will let you do all sorts of cool things. You can take a screenshot of what's showing on the phone. You can debug, look at logs, etc. It also shows you the filesystem for your application. Since your application is a its own Linux account, it has its own set of files and applications. And, if you are like mine and have persisted data using the built-in sqlite3 database, the database is also there on the filesystem. If your app is called foo.myapp then it's under /data/data/foo.myapp/databases.
There will be a file that is the name of the database along with any tables.

Let's say your database is called MyDatabase and you have a table, mytable.

Now click on the databases folder and click the action menu item for that view "Pull a file from this device". It will actually copy this whole directory to your local filesystem.

Now, hopefully at this point you are in Linux and already have sqlite3 installed. You do run Ubuntu right? :-)

Bring up a shell. Fire up sqlite3 like so:



That's it. It should list the contents of your table (assuming you have a column named col1). Other than that, it's standard sqlite3 stuff.

There should be a lot of neurons firing right now about what this means. Perhaps involving snycing. You can add files back to the device. And, this sort of thing can be done with a standalone emulator, so no eclipse is required.

Enjoy!