Пример #1
0
 /**
  * Sets the {@link AccessibilityServiceInfo} which informs the system how to handle this {@link
  * AccessibilityService}.
  *
  * @param feedbackType The type of feedback this service will provide. Note: The feedbackType
  *     parameter is an bitwise or of all feedback types this service would like to provide.
  */
 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
   info.notificationTimeout = EVENT_NOTIFICATION_TIMEOUT_MILLIS;
   // we want to receive accessibility events only from certain packages
   info.packageNames = PACKAGE_NAMES;
   setServiceInfo(info);
 }
  // set the accessibility filter to
  // watch only for google voice notifications
  @Override
  protected void onServiceConnected() {
    super.onServiceConnected();
    connected = true;

    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    // We are interested in all types of accessibility events.
    info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
    // We want to provide specific type of feedback.
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    // We want to receive events in a certain interval.
    info.notificationTimeout = 100;
    // We want to receive accessibility events only from certain packages.
    info.packageNames = new String[] {Helper.GOOGLE_VOICE_PACKAGE};
    setServiceInfo(info);
  }