Because accessibility services are able to explore and interact with on-screen content, a user has to explicitly enable services in Settings > Accessibility. Once a service is enabled, the system will start it automatically and bind it to the accessibility APIs.
Make sure you declare your service in your application manifest:
<service android:name=".MyAccessibilityService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
. . .
</service>
You'll also need to provide configuration for your service, either by overriding setServiceInfo(AccessibilityServiceInfo) or adding a meta-data attribute and XML config file.
The meta-data attribute goes in your <service> declaration after the <intent-filter> tag and looks like this:
<meta-data android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
The XML config that you're referencing (in this case, accessibilityservice.xml) looks like this:
<accessibility-service
android:accessibilityEventTypes="typeViewClicked|typeViewFocused"
android:packageNames="foo.bar, foo.baz"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100"
android:accessibilityFlags="flagDefault"
android:settingsActivity="foo.bar.TestBackActivity"
android:canRetrieveWindowContent="true"
. . .
/>
There's more information on which tags you can use at http://developer.android.com/reference/android/R.styleable.html#AccessibilityService
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…