UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper();
automationWrapper.connect();
automationWrapper.getUiAutomation().setOnAccessibilityEventListener(
new OnAccessibilityEventListener() {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss.SSS");
System.out.println(String.format("%s %s",
formatter.format(new Date()), event.toString()));
}
});
// there's really no way to stop, essentially we just block indefinitely here and wait
// for user to press Ctrl+C
synchronized (mQuitLock) {
try {
mQuitLock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
automationWrapper.disconnect();