Enhancement on Soft-Key Detection

With many thanks to Graham over at the Nokia Discussion forums I came across an interesting Wiki article (Platform independent key events processing) which provides a class that tries to determine common non-standard keycodes for a variety of handsets. The second handset that I tested was an LG KS360, unfortunately this detection class was unable to detect the soft key buttons.

I have combined my welcome screen based soft-key detection into that class as a fail-safe, and this seems to be working great. So, where possible the correct keycodes are detected by working out the device vendor, and then where all else fails, accept the first non-standard keycode that is returned from the welcome screen for the left soft-key.

I have also added a SOFTKEY_GUESSED field which indicates if the left soft-key value was guessed. If it was, then you can decide whether or not to allow other non-standard keys to represent the right soft-key. You might decide against guessing the right soft-key in more critical scenarios where data could potentially be lost by pressing another unrelated button on the keypad.

The combination of these two techniques seems to provide a much better solution.

Generic soft key detection in J2ME

As many of you are aware, the soft key buttons on a mobile phone are general purpose buttons that are reused over and over again. On most handsets there are two of these directly beneath the screen (one on the left, and one on the right).

In a recent project I needed to be able to detect when the left and right soft keys were being pressed, but unfortunately, J2ME does not define a standard key code. Instead it is up to the developer to specify different codes for all of the different phones in their target audience.

Two solutions came to mind:

  1. Compile the application for each target handset (perhaps overkill given that this be the only difference).
  2. Get the user to specify which button is which (even if they do not realize this!).

Continue reading