Search code examples
androiddelphidelphi-xe8android-hardware

How to detect if the device has hardware BACK and MENU keys in DELPHI


Is there a way how to detect if the user has access to the device BACK and MENU keys?

In ANDROID it's a simply code:

boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

But how do it in DELPHI?


Solution

  • To determine the presence of a hardware keys, this method is the easiest:

    .
    .
    uses
      Androidapi.KeyCodes,
      Androidapi.JNI.GraphicsContentViewText,
    .
    .
      TJKeyCharacterMap.JavaClass.deviceHasKey(AKEYCODE_BACK) //To detect hardware BACK
      TJKeyCharacterMap.JavaClass.deviceHasKey(AKEYCODE_MENU) //To detect hardware MENU
    .
    .
    

    Result for deviceHasKey is Boolean.

    All keycode constants can be found in unit Androidapi.KeyCodes.