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.

rds
  • 26,253
  • 19
  • 107
  • 134
heathkit
  • 573
  • 5
  • 12

1 Answers1

-3

Based on:

Create a Service extending AccessibilityService:

public class TestService extends AccessibilityService {

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

}

In your manifest file:

<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>

In your resources (xml folder), create accessibilityservice.xml:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
                       android:accessibilityEventTypes="typeNotificationStateChanged"
                       android:accessibilityFeedbackType="feedbackAllMask"
                       android:notificationTimeout="100" />
Community
  • 1
  • 1
Alejandro Colorado
  • 6,034
  • 2
  • 28
  • 39
  • I see that last paragraph copy/pasted all over, and I want to clarify for future readers that the `android:accessibilityEventTypes="typeNotificationStateChanged"` will need to be changed to the kinds of events you are interested in receiving. If you want all events, use `typeAllMask`. – kurtzbot Sep 10 '13 at 21:29
  • 2
    How it helps him to test it? – Maor Hadad Oct 31 '18 at 15:37
  • 1
    how is this related to testing of accessibility service? – Nauman Ash Oct 11 '19 at 11:41