SDK で提供される API サンプルの ClockBackService.java のコードを次に示します。
/**
* Sets the {@link AccessibilityServiceInfo} which informs the system how to
* handle this {@link AccessibilityService}.
*
* @param feedbackType The type of feedback this service will provide.
* <p>
* Note: The feedbackType parameter is an bitwise or of all
* feedback types this service would like to provide.
* </p>
*/
private void setServiceInfo(int feedbackType) {
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
// We are interested in all types of accessibility events.
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
// We want to provide specific type of feedback.
info.feedbackType = feedbackType;
// We want to receive events in a certain interval. (milliseconds)
info.notificationTimeout = EVENT_NOTIFICATION_TIMEOUT_MILLIS;
// We want to receive accessibility events only from certain packages.
info.packageNames = PACKAGE_NAMES;
setServiceInfo(info);
}
サンプル サービスでは、これは onServiceConnected から呼び出されてサービスを初期化し、続いて提供されるフィードバックの種類を変更します。