0

How to invoke setServiceInfo method in AccessibilityService on runtime

@Override
protected void onServiceConnected() {
    // TODO Auto-generated method stub
    log("onServiceConnected");
    setServiceInfo();
}

I need to dynamically change the serviceInfo values on runtime based on certain scenarios. I could not find a way to restart the service or call setServiceInfo from another class.

Please suggest me on this, Thanks

4

1 回答 1

2

以下是 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 调用它来初始化服务并随后更改所提供的反馈类型。

于 2012-06-20T04:08:14.437 回答