Accessibility Service for my app is not working if

2020-07-18 03:23发布

问题:

Accessibility Service is not binding with my app if I not doing uncheck of Accessibility Service option under Settings -> Accessibility before I do uninstall my app.

Note: To make it again work I need to restart my phone

Can any one please suggest me on how to safely reinstall my app without disabling Accessibility Service

回答1:

I was successful at reinstalling the service while it was enabled (and continue receiving events after that), after tweaking the service settings.

I changed android:packageNames="com.example.android.apis" (got this from tutorials) into android:packageNames="@null"

As of today I have in the xml config part (for JB):

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/accessibility_description"
    android:packageNames="@null"
    android:accessibilityEventTypes="typeNotificationStateChanged"
    android:accessibilityFlags="flagDefault"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:notificationTimeout="100"
    android:canRetrieveWindowContent="false"
/>

and in the Java part (for pre-JB, in service's onServiceConnected() ):

    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
    info.notificationTimeout = 100;
    info.packageNames = null;
    info.feedbackType = AccessibilityServiceInfo.DEFAULT;
    this.setServiceInfo(info);

I wish this can help with your own case...