Add Geocorder.isImplemented()

The Geocorder interface is not part of the Android core.  It
requires a backend service which may or may not be available
on a device.  The new isImplemented static method allows
apps to discover whether the Geocorder is in fact available
on the device.

Change-Id: I2b5cf7bcc9cce4766bcbb156e91edf34b01f9296
This commit is contained in:
Mark Vandevoorde
2010-05-21 15:43:26 -07:00
parent 11c6847d59
commit 01ac80b715
4 changed files with 36 additions and 1 deletions

View File

@@ -40,7 +40,9 @@ import java.util.List;
*
* The Geocoder class requires a backend service that is not included in
* the core android framework. The Geocoder query methods will return an
* empty list if there no backend service in the platform.
* empty list if there no backend service in the platform. Use the
* isImplemented() method to determine whether a Geocoder implementation
* exists.
*/
public final class Geocoder {
private static final String TAG = "Geocoder";
@@ -48,6 +50,23 @@ public final class Geocoder {
private GeocoderParams mParams;
private ILocationManager mService;
/**
* Returns true if the Geocoder methods getFromLocation and
* getFromLocationName are implemented. Lack of network
* connectivity may still cause these methods to return null or
* empty lists.
*/
public static Boolean isImplemented() {
IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE);
ILocationManager lm = ILocationManager.Stub.asInterface(b);
try {
return lm.geocoderIsImplemented();
} catch (RemoteException e) {
Log.e(TAG, "isImplemented: got RemoteException", e);
return false;
}
}
/**
* Constructs a Geocoder whose responses will be localized for the
* given Locale.