11

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

这是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"
/>

无障碍服务是根据系统注册的,可以启动或停止,如果我在应用程序中更改它们并重新安装应用程序,服务设置就会改变。

但是该服务不再绑定到我的应用程序。的onServiceConnected方法ForegroundMonitor没有被调用。

我在这里发现了一些类似的问题:

我已经尝试了唯一建议的解决方案,但它不适用于我的情况。

根据我的测试,该问题仅出现在 Android 5.0.1 上。Android 2.3.3 应用正常,服务绑定成功。

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

更新

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

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

提前致谢。

4

0 回答 0