1

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?

1 Answers1

1

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.

pudnivec74
  • 845
  • 1
  • 8
  • 22
  • see [this](http://stackoverflow.com/a/23181183/80901): answer comments: `However, you can never be 100% sure about this, since manufacturers can implement deviceHasKey wrong.` ... for example the OnePlus seems to have it wrong – mjn Sep 08 '15 at 12:42
  • It gets you the truth, but this code can be used for the vast majority of devices. Of course there will be exceptions in devices. If all manufacturers used the unwritten standards will be programming a lot easier. – pudnivec74 Sep 08 '15 at 12:48
  • It conforms for me. On devices that I have at home it works. Thanks pudnivec74 –  Sep 08 '15 at 12:59