Exception Message Service

You can implement an exception message service for resolving localized messages using error codes. The exception class uses the exception message service to load resource bundles and look up error messages based on an error code. You can use a default message provider, ExceptionMessageServiceImpl, or create a custom provider by implementing your own ExceptionMessageService.

To resolve localized messages, implement the ExceptionMessageService interface.

public class CustomExceptionMessageService implements ExceptionMessageService
{
  public String getMessage(int errorCode)
  {
    String msg = null;

    msg = "getMessage(" + errorCode + ")";

    return msg;
  }

  public String getMessage(int errorCode, String localeName)
  {
    String msg = null;

    msg = "getMessage(" + errorCode + "," + localeName + ")";

    return msg;
  }
}

A default implementation, ExceptionMessageServiceImpl allows the default English resource to look up an error message using an error code. You can follow these steps to add other localized resources for the Android platform without implementing a custom message service.

  1. Get the default property file "SUPErrorMessage_en.properties" (included in the resources folder in the Mobile SDK for the Android platform) and localize it to another language file, for instance, "SUPErrorMessage_de.properties".
  2. Add the new property file into the src folder of the application.
  3. Register the default implementation "ExceptionMessageServiceImpl" in the application code:
    ServiceRegistry.getInstance().registerService(ExceptionMessageService.class,
    ExceptionMessageServiceImpl.getInstance());
  4. Use the localized error message in the application.
  5. You can unregister the exception message service to cancel the use of the localized error message:
    ServiceRegistry.getInstance().unregisterService(ExceptionMessageService.class);