Reputation: 1
I'm trying to implement accessibility service to handle the keyevents(onKeyDown/onKeyUp) of a Device HW key(ex: Volume key/Power key), which can process certain operations. But I want handle this event only if no other apps are handling this Device key for that specific events(Key up/Key Down). To put it simple, I want these events to be handled as a fallback incase no 3rd party apps are handling.
Current implementation as follows.
override fun onKeyEvent(event: KeyEvent?) : Boolean{
if (event?.keyCode != KEYCODE_HW) {
return false
}
when (event?.action) {
0 -> {
mDowntime = SystemClock.elapsedRealtime().toInt()
}
1 -> {
// Do something
}
}
}
I tried to check the android document on Keyevents and keycode and fallback flags, but I'm unable to find any proper answer which can handle current scenario. And as per my understanding, Accessibility service will be the first to intercept the key events, when implemented before dispatching to the other apps/PhoneWindowManager.
Is there any way to do this? Any answer would be appreciated.
Upvotes: 0
Views: 29