应用程序更新后未绑定辅助功能服务

Sta*_*tan 9 android accessibilityservice android-5.0-lollipop

我有一个完美运行的应用程序与可访问性服务.到目前为止,它一直在按预期工作.当我尝试构建新的更新版本时,问题出现了.与可访问性服务相关的代码中没有任何更改.但该服务不再绑定到更新的应用程序.日志中没有错误或警告.这是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>
Run Code Online (Sandbox Code Playgroud)

这是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"
/>
Run Code Online (Sandbox Code Playgroud)

可访问性服务是根据系统注册的,可以启动或停止,如果我在应用程序中更改它们并重新安装应用程序,服务设置会更改.

但该服务不再绑定到我的应用程序了.该onServiceConnected方法ForegroundMonitor不叫.

我在SO上发现了一些类似的问题:

我已经尝试了唯一的建议解决方案,但它在我的情况下不起作用.

根据我的测试,问题只出现在Android 5.0.1上.在Android 2.3.3上,该应用程序正常运行,服务绑定成功.

有人可以共享这个问题的解决方案,这可能是一个Android错误吗?

UPDATE

我刚刚找到了一个解决方法:重命名扩展的类AccessibilityService(在我的情况下为ForegroundMonitor)就足够了,例如通过添加版本控制后缀.此方法的缺点是用户必须重新启用系统中的新辅助功能服务,因为它被视为另一个.理想情况下,如果服务一旦启用,应用程序的更新不应要求此项.

所以我仍然对解决方案感兴趣 - 更方便的解决方案.

提前致谢.