java-memidplcduisoftkeys

J2ME Soft Key Wrapper


Reading some articles, told me that soft keys varies between devices. Some says -6 or -21 for left soft key and -7 or -22 for right soft key. Given this situation, is there any good wrapper or function or best practice to handle it properly?

If not possible for ALL devices, what is the best way to support most devices? with minor or no hack at all?


Solution

  • To give you a feel for the scope of the problem have a look at this table of keycodes.

    Omermuhammed's approach is a good one if you are able to vary the JAD content depending on the target handset, for example by looking at the user-agent header field in a download request from an on-handset web browser.

    If you cannot identify the handset until the app has been delivered, you could look at something like this that basically determines the host handset at run time and sets the keycode mappings appropriately. Looks cumbersome to me though.

    Lastly, if your application uses a subset of codes you may be able to get away with hard-coded lists - for some codes there are no or few collisions (LEFT is usually either -3 or -61, and those codes usually don't mean something else). Again, not an ideal approach.

    Final suggested resources for you: wurfl or user agent strings, and the J2MEPolish devices database for device keycodes.