ANSWER:
First if you are using the emulator, try setting the "target" for the AVD device to one of the "Google APIs" instead of the basic "Android" sdk. So if you want to target 2.3.3 use "Google APIs (Google Inc.) - API Level 10" and not "Android 2.3.3 - API Level 10".
BACKGROUND INFO
The Google APIs addon includes a backend service implementation(search "geocoder backend") that is required for the Geocoder.getFromLocation...
methods to work.
The Geocoder class requires a backend service that is not included in the core android framework
That is why your AVD must target Google APIs for these methods to work. If that doesn't work try testing on a real device. Other than a possible bug, the reason for getting this exception is either a problem with the internet/lack of connection, or more likely there is no backend service on that device.
Supposedly most devices that include Google services and apps like Maps, etc will have a backend implemented. I don't know how accurate this is.
There is also a method starting with API9, Geocoder.isPresent()
that will return true if there is a backend implementation present. However, I have found this to be unreliable since testing it on an Amazon Kindle Fire returned true, but when making a getFromLocationName()
call I still got an IOException: Service Not Available
It seems the most reliable way to determine if a backend is present is to just make the getFromLocation...
call and see if your addresses
field is null
or if the List
is empty. There is a bit of ambiguity in that these methods may also return a null
or empty list if there are simply no matches found.