Created
December 10, 2015 07:29
-
-
Save MFlisar/f7f32c386d77751648f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WindowChangeDetectingService extends AccessibilityService { | |
@Override | |
protected void onServiceConnected() { | |
super.onServiceConnected(); | |
//Configure these here for compatibility with API 13 and below. | |
AccessibilityServiceInfo config = new AccessibilityServiceInfo(); | |
config.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;// | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED; | |
config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;// | AccessibilityServiceInfo.FEEDBACK_SPOKEN; | |
if (Build.VERSION.SDK_INT >= 16) | |
//Just in case this helps | |
config.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS; | |
setServiceInfo(config); | |
} | |
@Override | |
public void onAccessibilityEvent(AccessibilityEvent event) | |
{ | |
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) | |
{ | |
String packageName = event.getPackageName() != null ? event.getPackageName().toString() : ""; | |
String activityName = event.getClassName() != null ? event.getClassName().toString() : ""; | |
// do something with the information | |
// ... | |
} | |
else if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) | |
{ | |
L.d(this, "event: " + event.toString()); | |
} | |
} | |
@Override | |
public void onInterrupt() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
don't forget to add the service to the manifest:
The xml looks something like following: