I am trying to detect if the keyboard is active or not (outside my application) using the accessibility service. To do this, I tried to read the βselect keyboardβ notifications (if multiple keyboard is enabled). The following code is used.
public class KeyboardWatcher extends AccessibilityService { boolean isConnected = false; @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { final String packagename = String.valueOf(event.getPackageName()); Log.d("Package", packagename); String msg = ""; List<CharSequence> s = event.getText(); if(s.iterator().hasNext()) { msg += s.iterator().next().toString(); Log.d("MSG", msg); }else{ Log.d("TYPE", event.getEventType()+""); } }else{ Log.d("EVENT TYPE__",event.getEventType()+""); final String packagename = String.valueOf(event.getPackageName()); Log.d("PNE", packagename); } } protected void onServiceConnected() { if (isConnected) { return; } AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK; setServiceInfo(info); isConnected = true; } }
Now all notifications are registered by the application, except for the "Select Keyboard" notification. How to read this notice is possible.
thanks
source share