> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/reusable-content/guide/guide-basics-tools-interceptannohandling1.md).

# guide/basics/tools/interceptAnnoHandling1

In `BasicAnnotationListener.onInterceptAnnotationHandling(Annot, Bundle, int)`, the second parameter, `Bundle`, contains the name of the action intercepted by this function, as well as some extra information. You can get the name of the intercepted action by calling `bundle.getString(Tool.METHOD_FROM)`:

{% tabs %}
{% tab title="Java" %}

```java
public boolean onInterceptAnnotationHandling(Annot annot, Bundle extra, ToolMode toolMode) {
    if (extra != null && extra.containsKey(Tool.METHOD_FROM)) {
        String methodCalling = extra.getString(Tool.METHOD_FROM);
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
override fun onInterceptAnnotationHandling(annot: Annot?, extra: Bundle?, toolMode: ToolMode): Boolean {
    if (extra != null && extra.containsKey(Tool.METHOD_FROM)) {
        val methodCalling = extra.getString(Tool.METHOD_FROM)
    }
}
```

{% endtab %}
{% endtabs %}

To get extra information, first obtain the information keys by calling `bundle.getStringArray(Tool.KEYS)`:

{% tabs %}
{% tab title="Java" %}

```java
String[] paramKeys = extra.getStringArray(Tool.KEYS)
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val paramKeys = extra!!.getStringArray(Tool.KEYS)
```

{% endtab %}
{% endtabs %}

Then, you can get the information values by looping on each key obtained above:

{% tabs %}
{% tab title="Java" %}

```java
public boolean onInterceptAnnotationHandling(Annot annot, Bundle extra, ToolMode toolMode) {
    if (extra != null && extra.containsKey(Tool.KEYS)) {
        String[] paramKeys = extra.getStringArray(Tool.KEYS);
        if (paramKeys != null) {
            for (String key : paramKeys) {
                // Gets the information value
                Object param = extra.get(key);
            }
        }
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
override fun onInterceptAnnotationHandling(annot: Annot?, extra: Bundle?, toolMode: ToolMode): Boolean {
    if (extra != null && extra.containsKey(Tool.KEYS)) {
        val paramKeys = extra.getStringArray(Tool.KEYS)
        if (paramKeys != null) {
            for (key in paramKeys) {
                // Gets the information value
                val param = extra.get(key)
            }
        }
    }
}
```

{% endtab %}
{% endtabs %}

#### Common use cases

**Links**

{% tabs %}
{% tab title="Java" %}

```java
mToolManager.setBasicAnnotationListener(new ToolManager.BasicAnnotationListener() {
    @Override
    public boolean onInterceptAnnotationHandling(Annot annot, Bundle extra, ToolMode toolMode) {
        try {
            // Intercept clicking link annotation by return true
            if (annot.getType() == Annot.e_Link) {
                Log.d("InterceptAnnot", "handling link annotation");
                return true;
            }
        } catch (PDFNetException e) {
            e.printStackTrace();
        }
        // return false so the other events can continue executing
        return false;
    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
mToolManager.setBasicAnnotationListener(object : ToolManager.BasicAnnotationListener {
    override fun onInterceptAnnotationHandling(annot: Annot?, extra: Bundle?, toolMode: ToolMode?): Boolean {
        try {
            // Intercept clicking link annotation by return true
            if (annot!!.type == Annot.e_Link) {
                Log.d("InterceptAnnot", "handling link annotation")
                return true
            }
        } catch (e: PDFNetException) {
            e.printStackTrace()
        }
        // return false so the other events can continue executing
        return false
    }
})
```

{% endtab %}
{% endtabs %}

**Form widgets**

{% tabs %}
{% tab title="Java" %}

```java
mToolManager.setBasicAnnotationListener(new ToolManager.BasicAnnotationListener() {
    @Override
    public boolean onInterceptAnnotationHandling(Annot annot, Bundle extra, ToolMode toolMode) {
        try {
            // Intercept clicking widget annotation by return true
            if (annot.getType() == Annot.e_Widget) {
                Log.d("InterceptAnnot", "handling widget annotation");
                return true;
            }
        } catch (PDFNetException e) {
            e.printStackTrace();
        }
        // return false so the other events can continue executing
        return false;
    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
mToolManager.setBasicAnnotationListener(object : ToolManager.BasicAnnotationListener {
    override fun onInterceptAnnotationHandling(annot: Annot?, extra: Bundle?, toolMode: ToolMode?): Boolean {
        try {
            // Intercept clicking widget annotation by return true
            if (annot!!.type == Annot.e_Widget) {
                Log.d("InterceptAnnot", "handling widget annotation")
                return true
            }
        } catch (e: PDFNetException) {
            e.printStackTrace()
        }
        // return false so the other events can continue executing
        return false
    }
})
```

{% endtab %}
{% endtabs %}

**Full sample code**

For example, the following code demonstrates several scenarios and how you can get notified **before** each: clicking on a radio button, changing the annotation opacity, and clicking on a link. See the comments in the code for details.

{% tabs %}
{% tab title="Java" %}

```java
mToolManager.setBasicAnnotationListener(new ToolManager.BasicAnnotationListener() {
    @Override
    public boolean onInterceptAnnotationHandling(Annot annot, Bundle extra, ToolMode toolMode) {
        /*
            For example, when a radio button is clicked, this code will print:
            calling method: handleWidget
            property: OTHER
        */
        if (extra != null && extra.containsKey(Tool.METHOD_FROM)) {
            String methodCalling = extra.getString(Tool.METHOD_FROM);
            Log.d("InterceptAnnot", "calling method " + methodCalling);
            AnnotationProperty.Property property = AnnotationProperty.getProperty(methodCalling);
            Log.d("InterceptAnnot", "property: " + property);
        }
        /*
            For example, when annotation opacity is about to be changed to 50%, this code will print:
            calling method: editOpacity
            property: OPACITY
            key: opacity
            value: 0.5
        */
        if (extra != null && extra.containsKey(Tool.KEYS)) {
            String[] paramKeys = extra.getStringArray(Tool.KEYS);
            if (paramKeys != null) {
                for (String key : paramKeys) {
                    Object param = extra.get(key);
                    Log.d("InterceptAnnot", "key: " + key);
                    Log.d("InterceptAnnot", "value: " + param.toString());
                }
            }
        }
        try {
            // Intercept radio button from clicking by return true
            if(annot.getType() == Annot.e_Widget) {
                Widget w = new Widget(annot);
                Field field = w.getField();
                if (field != null && field.isValid() && field.getType() == Field.e_radio) {
                    return true;
                }
            }
            // Intercept clicking link annotation by return true
            if (annot.getType() == Annot.e_Link) {
                Log.d("InterceptAnnot", "handling link annotation");
            }
        } catch (PDFNetException e) {
            e.printStackTrace();
        }
        // return false so the other events can continue executing
        return false;
    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
mToolManager.setBasicAnnotationListener(object : ToolManager.BasicAnnotationListener {
    override fun onInterceptAnnotationHandling(annot: Annot?, extra: Bundle?, toolMode: ToolMode?): Boolean {
        /*
      For example, when a radio button is clicked, this code will print:
      calling method: handleWidget
      property: OTHER
      */
        if (extra != null && extra.containsKey(Tool.METHOD_FROM)) {
            val methodCalling = extra.getString(Tool.METHOD_FROM)
            Log.d("InterceptAnnot", "calling method " + methodCalling)
            val property = AnnotationProperty.getProperty(methodCalling)
            Log.d("InterceptAnnot", "property: " + property)
        }
        /*
      For example, when annotation opacity is about to be changed to 50%, this code will print:
      calling method: editOpacity
      property: OPACITY
      key: opacity
      value: 0.5
      */
        if (extra != null && extra.containsKey(Tool.KEYS)) {
            val paramKeys = extra.getStringArray(Tool.KEYS)
            if (paramKeys != null) {
                for (key in paramKeys) {
                    val param = extra.get(key)
                    Log.d("InterceptAnnot", "key: " + key)
                    Log.d("InterceptAnnot", "value: " + param.toString())
                }
            }
        }
        try {
            // Intercept radio button from clicking by return true
            if (annot!!.type == Annot.e_Widget) {
                val w = Widget(annot)
                val field = w.getField()
                if (field != null && field.isValid() && field.getType() === Field.e_radio) {
                    return true
                }
            }
            // Intercept clicking link annotation by return true
            if (annot!!.type == Annot.e_Link) {
                Log.d("InterceptAnnot", "handling link annotation")
            }
        } catch (e: PDFNetException) {
            e.printStackTrace()
        }
        // return false so the other events can continue executing
        return false
    }
})
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/reusable-content/guide/guide-basics-tools-interceptannohandling1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
