Function Buttons¶
Context¶
Some models of Famoco devices (see "Compatible Devices") have function buttons, which don't serve one of the basic functions of usual buttons on Android devices (i.e. Power On/Off, Volume Up/Down, etc). These are often called "customizable" or "personalizable" buttons on the device's User Manuals.
These buttons allow you to create custom integrations with your devices, by linking the pressing of that button to a specific function inside of your business applications. It is a way to bridge the gap between the hardware and the software.
Sample code¶
The Kotlin code below allows you to listen to KeyEvents in your business applications, and launch whichever function you want upon the button press.
For more information, please check the Android API reference about KeyEvents.
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
return when (keyCode) {
KeyEvent.KEYCODE_F1 -> {
myFunction()
true
}
KeyEvent.KEYCODE_F2 -> { // If the device has a second function button
myOtherFunction()
true
}
else -> super.onKeyUp(keyCode, event)
}
}