Android applications that use the MyLocationOverlay class crash on the new Droid X


Update: July 23, 2010

I got notified by users that Motorola and Verizon came out yesterday with an update for the Droid X phones, which among other things fixes the issue described in this post below.


As soon as the new Motorola Droid X came out I started getting reports that my applications would crash on it.

The description I was getting from people was that the application would start, then it would show the Google map and start moving the map and zooming in on to their current location and then all of a sudden the app would crash. By crash I mean they get taken back to the phone’s home screen. No “Force Close” dialog pops up… nothing… just gets back to the home screen.

If both the GPS and the Wireless Networks are turned off from the Locations settings then the applications would work fine, but of course that means that the current location of the device would be impossible to find.

At this point I knew that the problem had to do with either the LocationManagers or the LocationOverlays but I had no way of finding out exactly what the problem was until I could get my hands on a Droid X phone and connect it to my computer to look at the execution stack.

Well it turns out the problem is with the default MyLocationOverlay class. The Droid X phones throw an exception when they try to draw the dot showing the location of the device:

E/AndroidRuntime(10458): Uncaught handler: thread main exiting due to  uncaught exception
E/AndroidRuntime(10458): java.lang.ClassCastException:  android.graphics.drawable.BitmapDrawable
E/AndroidRuntime(10458): 	at com.google.android.maps.MyLocationOverlay.getLocationDot(MyLocationOverlay.java:180)
E/AndroidRuntime(10458): 	at com.google.android.maps.MyLocationOverlay.drawMyLocation(MyLocationOverlay.java:561)

Another developer (rgfindl) who had the same problem like I did and who had already made the trip to the Verizon store gave me the above stack trace.

Several possible solutions popped into my head:

1. Stop using the MyLocationOverlay class and start relying only on the LocationManager classes and draw/redraw my current location onLocationChanged.
2. Extend from MyLocationOverlay class and override the draw method.
3. Stop supporting the Droid X.

None of these solutions are ideal with the last one being almost unacceptable.

Luckily the same developer also gave me a link to a solution implementing the 2nd option above, so I did not even have to code it myself. Apparently that is not the first time Motorola phones (Motorola Cliq and Motorola Dext) have a problem with this class. Most likely their builds are missing the drawable resource.

Anyway, the solution consists of the .java file that implements the FixedMyLocationOverlay class, which inherits from the default MyLocationOverlay class and overrides the drawMyLocation method. And a .png file with a dot that will be representing the current location on the map.

Just use this derived class FixedMyLocationOverlay instead of the default MyLocationOverlay. If you look at the implementation of the drawMyLocation method, you will see that if the phone has no problem it will use the default implementation of the parent class, but if it throws an exception it will use the custom code to draw the location.

I would think that there are a lot of applications in the Android Market right now that use the default MyLocationOverlay class and all of them will be crashing on the new Droid X until either Motorola gets their act together or the developers realize the issue and work around it.

Monday, July 19th, 2010 Android, Eclipse, Java, Programming No Comments

Just Upgraded my Nexus One from Android 2.1 to Android 2.2

The latest Android OS version 2.2 (”Froyo”) was announced at the Google I/O conference on the 11th of May. As you already probably know it adds multiple enhancements like tethering, wifi hotspot functionality, full support for Flash, etc. Since I use my Nexus One phone for Android development, I did not want to download the update from Google and then install it with adb. I just wanted to wait for the over the air update.

And to my surprise, the first time I looked at my phone this morning, I had this message on the screen:

Android 2.2 Upgrade Message

Android 2.2 Upgrade Message

I was not sure how long it would take, so I just hit “Install Later”. Then a couple of hours later, when I was ready, I just went to Settings -> About Phone -> Software Update and hit “Restart & Install”:

Android 2.2 Settings -> About Phone -> System Updates

Android 2.2 Settings -> About Phone -> System Updates

The phone rebooted and started the upgrade. The whole process with the installation took less than 5 minutes.

I am not going to go into details what the features of Android 2.2 are. There are so many announcements and blog posts on this matter already out there…

But what I am going to say is that Android is the leading OS in the mobile phone market right now. I can say this definitively, since I have been using iPhones for the past 2 years. I have a 3G and a 3GS phones. I encourage any iPhone user to go and check out an Android device. Please do not look at the low end hardware that runs Android (like the Cliq, the old G1, etc.). Check out the HTC Evo, the HTC Incredible, the Nexus One etc. See for yourselves before you make your decision to get another phone and lock into a 2 year contract. I will mention only a few things you will discover on the Android device that your phone probably does not have right now:

  1. Turn by turn voice navigation
  2. Built in tethering
  3. Built in WiFi hotspot capability supporting multiple devices
  4. Full support for Flash
  5. Full blown multitasking on the OS level (no need for the programmer to do anything special)
  6. Integrated speech recognition across the board. Voice input could be used anywhere in place of the text input.
  7. Over the air updates and syncing. That means no iTunes or the like!

And many other features that I do not want to get into details right now. I am sure you can fill in the gaps for yourselves…

Friday, July 2nd, 2010 Android, Apple, Linux No Comments

Find the Geopgraphical Location of an IP Address

There are a few applications that give the geographical location of an IP address *. My favorite one is VisualRoute. It not only maps the location of the source and destination IP addresses, but also all the hops in between. The down side to it is that it is not available for Linux and it costs $50 per user.

The http://mapulator.com site gives you pretty much the same information online for free, but it has been down for quite some time now.

Lately I have been using http://whatismyipaddress.com/ip-lookup. But it only maps the destination IP address.

If anyone knows of a Linux application that would map all the hops and the final IP destination, please leave a comment!

* IP addresses do not have a geographical location per se. Any program that maps IP addresses can only give you where the whole class of IP addresses (that the specified IP address belongs to) is registered to be located at. They do this by querying a database that has that information. This is accurate down to a city level at best. Do not expect to find where someone lives by their IP address!

Monday, June 28th, 2010 Linux, Networking No Comments

Install Subversion and Subclipse for Eclipse on Ubuntu

If you do not have Eclipse installed yet, run:

sudo apt-get install eclipse

Install Subversion

sudo apt-get install subversion

Install the Subversion plugin for Eclipse

Get the Java bindings for Subversion:

sudo apt-get install libsvn-java

Now we are ready to install the plugins in Eclipse.

Open Eclipse.

Go to Help -> Install New Software

Then hit the “Add” button.

Put “Subclipse 1.6.x (Eclipse 3.2+)” under Name and “http://subclipse.tigris.org/update_1.6.x” under Location:

Add the libraries for Subclipse

Add the libraries for Subclipse

The above is for Elclips 3.2+ and Subversion 1.6.x.

If you have different Eclipse or Subversion versions, check this list and substitute accordingly:

Name: Subclipse 1.6.x (Eclipse 3.2+)
URL: http://subclipse.tigris.org/update_1.6.x

Name: Subclipse 1.4.x (Eclipse 3.2+)
URL: http://subclipse.tigris.org/update_1.4.x

Name: Subclipse 1.2.x (Eclipse 3.2+)
URL: http://subclipse.tigris.org/update_1.2.x

Name: Subclipse 1.0.x (Eclipse 3.0/3.1)
URL: http://subclipse.tigris.org/update_1.0.x

More info about the different versions: http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA

Then hit “OK”. You will now be presented with these options:

Subclipse Installation Options

Subclipse Installation Options

If you are unsure what Subclipse component you will need, you can check all of them. Also, keep in mind that you can always go back to this in the future and install/uninstall any of the components as needed.

Then “Next” and “Finish” on the subsequent screens.

After the plugins are installed, it will prompt you to restart Eclipse. Go ahead and do so.

You are not done yet. You need to fix the JavaHL.

Edit the eclipse.ini file:

sudo vi /usr/lib/eclipse/eclipse.ini

Add the following line under -vmargs:

-Djava.library.path=/usr/lib/jni

Here is what my eclipse.ini file looks like:

$ cat /usr/lib/eclipse/eclipse.ini
-startup
plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.0.200.v20090520
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-startup
--launcher.library
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-startup
/usr/lib/eclipse/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
--launcher.library
/usr/lib/eclipse/plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.0.200.v20090520
-vmargs
-Djava.library.path=/usr/lib/jni
-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=//usr/share/eclipse/dropins
-Xms40m
-Xmx256m
-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=//usr/share/eclipse/dropins

For more info on fixing JavaHL if you need it: http://subclipse.tigris.org/wiki/JavaHL#head-bb1dd50f9ec2f0d8c32246430c00e237d27a04fe

You should be able to use Subversion with Eclipse for your projects at this point.

Thursday, June 17th, 2010 Eclipse, Linux, Ubuntu No Comments

How to connect your Android phone to Ubuntu to do development, testing, installations or tethering

If you do any Android development in Ubuntu it is much better to test your applications on a real device rather than just relying on the emulator.

If you just connect the phone to the computer through USB and run adb devices you will find out that your phone is not recognized:

$ adb devices
List of devices attached
???????????? no permissions

This is easily fixable in Ubuntu. You have to add a line to a file in the /etc/udev/rules.d directory.

What line in which file depends on the manufacturer and model of the device. You can find out the Vendor ID number and Product ID number of the device by running (after you connected it via USB of course):

$ lsusb

For example, if you had a Nexus One connected you would get:

Bus 002 Device 004: ID 18d1:4e12

In this case the Vendor Id is “18d1″ and the Product ID is “4e12″. Please keep in mind that the Vendor ID for HTC changed from “0bb4″ to “18d1″. The older HTC phones like the G1 have a Vendor ID of “0bb4″.

Here is how to set up some of the major Android phones:

Step 1. Depending on your phone follow these instructions:

  • G1
    Create/edit a file in /etc/udev/rules.d called 51-android.rules:

    $ sudo gedit /etc/udev/rules.d/51-android.rules

    Add the following line to it and save it:

    SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c01″, MODE=”0666″

  • HTC Hero
    Create/edit a file in /etc/udev/rules.d called 51-android.rules:

    $ sudo gedit /etc/udev/rules.d/51-android.rules

    Add the following line to it and save it:

    SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c02″, MODE=”0666″

  • Motorola Droid
    Create/edit a file in /etc/udev/rules.d called 10-motorola-droid.rules:

    $ sudo gedit /etc/udev/rules.d/10-motorola-droid.rules

    Add the following line to it and save it:

    SUBSYSTEMS==”usb”, ATTRS{idVendor}==”22b8″, ATTRS{idProduct} ==”41db”, MODE=”0600″

  • Nexus One
    Create/edit a file in /etc/udev/rules.d called 99-android.rules:

    $ sudo gedit /etc/udev/rules.d/99-android.rules

    Add the following line to it and save it:

    SUBSYSTEM==”usb”, ATTRS{idVendor}==”18d1″, SYMLINK+=”android_adb”, MODE=”0666″

Step 2. Restart udev:

$ sudo restart udev

Check if the device is recognized:

$ adb devices

You may need to stop and start the adb server:

$ adb kill-server
$ adb start-server

You should be good to go…

Wednesday, May 12th, 2010 Android, Eclipse, Java 4 Comments

Search

 

Archive

July 2010
M T W T F S S
« Jun    
 1234
567891011
12131415161718
19202122232425
262728293031  

Other