8

I'm developing an Android application with a service that extends AccessibilityService. I'd like to be able to test this without mocking out the accessibility framework.

Does anyone have some recommendation on the best way to go about this?

I'd like to set up some different activities, move between them, and verify that my accessibility service responds correctly. I tried using a ServiceTestCase, but unfortunately that requires you set up the service yourself. I'm not sure how to set it up in a way similar to how the accessibility framework will set it up for me.

4

1 回答 1

-3

基于:

创建一个服务扩展AccessibilityService

public class TestService extends AccessibilityService {

  @Override
  public void onAccessibilityEvent(AccessibilityEvent evt) {
    //Your coding here   
  }

}

在您的清单文件中:

<service android:name=".TestService" android:enabled="true" >
    <intent-filter>
        <action android:name="android.accessibilityservice.AccessibilityService" />
    </intent-filter>
    <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" />
</service>

在您的资源(xml 文件夹)中,创建accessibilityservice.xml:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
                       android:accessibilityEventTypes="typeNotificationStateChanged"
                       android:accessibilityFeedbackType="feedbackAllMask"
                       android:notificationTimeout="100" />
于 2013-06-08T18:05:57.327 回答