Thursday, April 29, 2010

Android Emulator and Mock Location problem

As a foray into Android development it seemed a simple task to take my previous Palm Pre map application and "port" it to this environment.  Given the development environments are completely different, only little bits could actually be used.  Android is Java-based. 

So the first step is simply getting the basic app framework going that receives GPS data.  In this case, from a mock location provider that can be updated via DDMS which is the basic debugger that communicates with the emulator.  I haven't touched Java in years and didn't do much with it when I did.  It has the typical object oriented approach and syntax is something close to C++ so very easy to pick up.  One particular irritating part of Java is the one public class/one file approach.  The Java religion seems to like this aspect of the language; that of defining your organization as part of the language implementation. 

It didn't take long to craft the first draft and promptly run into issues.  A simple one; no mock location data.  Searching the web didn't net much except that I added the Google APIs along with the standard Android ones when creating the emulator image.  Once I did that, I ended up with the "Not updating R.layout.main" error after updating the project with the right API set.  After cleaning, building, building, searching, eventually the solution was to delete all the import libraries and re-add them.

Ok, back to the mock location issue.  The short solution - when you launch the image, click the "wipe user data" box.  For whatever reason, there is some history that prevented location info from working.  Possibly using a previous version of the emulator, not sure and at this point, don't care.  After that, sending GPS locations via GPX, KML, or single fixes worked great.  Google maps also started working again.  I'll run through the steps in gory detail for the rest of the app soon.  Hopefully, much sooner than my last post so long ago.

Now, off more Java fun....