My users will use TalkBack or some other available services. I would like to capture onKeyEvent events in our application, but the event is dispatched to allowed access services. I created the following basic accessibility service.
public class Accessibility_Service extends AccessibilityService { private String TAG = Accessibility_Service.class.getSimpleName(); @Override public boolean onKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); if (action == KeyEvent.ACTION_UP) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { Log.d("Hello", "KeyUp"); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { Log.d("Hello", "KeyDown"); } return true; } else { return super.onKeyEvent(event); } } @Override public void onServiceConnected() { Log.v(TAG, "on Service Connected"); AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.packageNames = new String[] { "com.camacc" }; info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK; info.notificationTimeout = 100; info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN; setServiceInfo(info); }
When I check logcat, I get no response. Can I use volume down events and events before TalkBack or other such availability services?
Thanks.
EDIT:
ADDED NEXT FLAG, STILL NOT LUCK:
info.flags = AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS;
source share