Hi I am building an accessibility service. I wanted to deal with the keyboard inputs, and also determine BACK key events. I guess my best shot is overriding the onKeyEvent() callback. But What I found out is that it is even never being called. I tried to add android:canRequestFilterKeyEvents="true" in configuration XML and also in the onServiceConnected module I added
info.flags=AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS;
info.flags=AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
setServiceInfo(info);
But still no luck. Looks like the even onKeyEvent is never raised.
If you want to handle the events of the homebutton and back button, you have to add this:
In your xml service declareted:
1-android:canRequestFilterKeyEvents="true"
2-Add flagRequestFilterKeyEvents to your android:accessibilityFlags
In your accessibility service class add onKeyEvent:
@Override
public boolean onKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
Log.e(TAG, "Back");
case KeyEvent.KEYCODE_HOME:
Log.e(TAG, "Home");
return false;
}
return super.onKeyEvent(event);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With