I'm developing an app that launches over other apps. Currently I'm using an AccessibilityService with setServiceInfo to listen to window changes, for specific package names, but I'm unable to change these package names dynamically.
private void setServiceInfo(String apps[]) {
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.notificationTimeout = 0;
info.packageNames = apps;
setServiceInfo(info);
}
The above code is how I'm setting the serviceInfo. I'm calling setServiceInfo onServiceConnected to first initialise and onAccessibilityEvents for any changes to the package names.
If accessibility service isn't the way to go about this, please suggest alternatives such as services etc.