I have a perfectly working application with an accessibility service. It works as expected. The problem arose when I tried to create a new updated version. In the accessibility service related code, nothing has changed. But the service is no longer tied to an updated application. There are no errors or warnings in the logs. Here is the part of manifest.xml :
... <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" /> <application android:name=".AppState" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:allowBackup="true"> // ... several activities, services and bootup receiver goes here... <service android:name=".ForegroundMonitor" android:label="@string/foreground_monitor_label" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> <intent-filter> <action android:name="android.accessibilityservice.AccessibilityService" /> </intent-filter> <meta-data android:name="android.accessibilityservice" android:resource="@xml/serviceconfig" /> </service> </application>
And here is serviceconfig.xml :
<?xml version="1.0" encoding="utf-8"?> <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" android:accessibilityEventTypes="typeViewClicked|typeViewFocused|typeWindowStateChanged" android:accessibilityFeedbackType="feedbackGeneric" android:notificationTimeout="1000" android:canRetrieveWindowContent="false" android:description="@string/foreground_monitor_about" />
The availability service is registered in accordance with the system, it can be started or stopped, and the service settings change if I change them in the application and reinstall the application.
But the service is no longer tied to my application. The onServiceConnected ForegroundMonitor method is not called.
I found several similar questions here on SO:
I tried only the proposed solution, but in my case this does not work.
According to my tests, the problem only occurs on Android 5.0.1. On Android 2.3.3, the application works fine and the service is successfully connected.
Can someone share a solution to this problem, which is supposedly an Android bug?
UPDATE
I just found a workaround: just rename a class that extends AccessibilityService (ForegroundMonitor in my case), for example, adding a version suffix. The disadvantage of this method is that users must reuse the new availability service on the system, because it is considered different. Ideally, updating the application should not require this if the service was once enabled.
Therefore, I am still interested in a solution - a more convenient solution.
Thanks in advance.