# ContentActionSelectedData

Artifact: [androidx.browser:browser](https://developer.android.com/jetpack/androidx/releases/browser) [View Source](https://cs.android.com/search?q=file:androidx/browser/customtabs/ContentActionSelectedData.java+class:androidx.browser.customtabs.ContentActionSelectedData) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

*** ** * ** ***


```
@ExperimentalCustomContentAction
public final class ContentActionSelectedData
```

<br />

*** ** * ** ***

Represents the data passed by a browser when a custom content action is triggered from a Custom Tab. When you add custom content actions using `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent.Builder#addCustomContentAction(androidx.browser.customtabs.CustomContentAction)`, the browser sends the `https://developer.android.com/reference/android/app/PendingIntent.html` associated with the selected action when the user triggers it. The browser includes specific extras in the `https://developer.android.com/reference/android/content/Intent.html` carried by the `https://developer.android.com/reference/android/app/PendingIntent.html`. This class provides a convenient way to access these extras, such as the current URL, the type of content interacted with, the ID of the triggered action, and potentially details about the specific element (like an image or link).

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#fromIntent(android.content.Intent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/Intent.html intent)` Creates a `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData` instance from the given `https://developer.android.com/reference/android/content/Intent.html`. |
| `int` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getClickedContentTargetType()()` Gets the specific type of content that was interacted with (e.g., via long-press) to trigger the custom content action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getImageAltText()()` Gets the alt text of the clicked element (e.g., an image or link), if available. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getImageDataUri()()` Gets a `https://developer.android.com/reference/android/net/Uri.html` pointing to the data of the clicked image, if the interacted element was an image and the browser supports providing this information. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getImageUrl()()` Gets the URL of the clicked image, if the interacted element was an image and the browser supports providing this information. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getIntent()()` Returns the underlying `https://developer.android.com/reference/android/content/Intent.html` object that this data was parsed from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getLinkText()()` Gets the visible text content of the clicked link, if the interacted element was a link and the browser provides this information. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getLinkUrl()()` Gets the URL of the clicked link, if the interacted element was a link (i.e., `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getClickedContentTargetType()` returns `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#CONTENT_TARGET_TYPE_LINK()`) and the browser supports providing this information. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getPageUrl()()` Gets the URL of the current web page in the Custom Tab when the action was triggered. |
| `int` | `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getTriggeredActionId()()` Gets the ID of the specific `https://developer.android.com/reference/androidx/browser/customtabs/CustomContentAction` that was triggered by the user. |

## Public methods

### fromIntent

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static @Nullable ContentActionSelectedData fromIntent(@Nullable Intent intent)
```

Creates a `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData` instance from the given `https://developer.android.com/reference/android/content/Intent.html`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/Intent.html intent` | The intent received from the browser's custom content action. This intent is expected to contain the relevant extras. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData` | A `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData` instance, or `null` if the provided intent is null. |

### getClickedContentTargetType

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public int getClickedContentTargetType()
```

Gets the specific type of content that was interacted with (e.g., via long-press) to trigger the custom content action.

| Returns |
|---|---|
| `int` | The `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent.ContentTargetType` integer value (e.g., `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#CONTENT_TARGET_TYPE_IMAGE()`, `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#CONTENT_TARGET_TYPE_LINK()`). Returns 0 if the extra is not present, which is not a valid target type and indicates the data was not sent or is malformed. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#EXTRA_CLICKED_CONTENT_TARGET_TYPE()` |   |

### getImageAltText

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable String getImageAltText()
```

Gets the alt text of the clicked element (e.g., an image or link), if available.

**Note:** The browser determines the length of the returned text, so it may be truncated. As such, the returned value is not guaranteed to be the complete, original text.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The alt text as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#EXTRA_CONTEXT_IMAGE_ALT_TEXT()` |   |

### getImageDataUri

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable Uri getImageDataUri()
```

Gets a `https://developer.android.com/reference/android/net/Uri.html` pointing to the data of the clicked image, if the interacted element was an image and the browser supports providing this information.

**Note:** The returned `Uri` points to a temporary file managed by the browser. Its contents should be copied to your app's persistent storage immediately if you need to access it later, as the file may be deleted. Do not store the Uri itself for long-term use. Please refer to https://developer.android .com/training/secure-file-sharing/share-file#GrantPermissions for more information.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | A `https://developer.android.com/reference/android/net/Uri.html` for the image data, or `null` if not present or Android version is below Tiramisu. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#EXTRA_CONTEXT_IMAGE_DATA_URI()` |   |

### getImageUrl

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable String getImageUrl()
```

Gets the URL of the clicked image, if the interacted element was an image and the browser supports providing this information.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The image URL as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#EXTRA_CONTEXT_IMAGE_URL()` |   |

### getIntent

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @NonNull Intent getIntent()
```

Returns the underlying `https://developer.android.com/reference/android/content/Intent.html` object that this data was parsed from. This can be useful for accessing any additional, non-standard extras that might have been included by the browser.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html` | The original `https://developer.android.com/reference/android/content/Intent.html`. |

### getLinkText

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable String getLinkText()
```

Gets the visible text content of the clicked link, if the interacted element was a link and the browser provides this information.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The link text as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#EXTRA_CONTEXT_LINK_TEXT()` |   |

### getLinkUrl

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable String getLinkUrl()
```

Gets the URL of the clicked link, if the interacted element was a link (i.e., `https://developer.android.com/reference/androidx/browser/customtabs/ContentActionSelectedData#getClickedContentTargetType()` returns `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#CONTENT_TARGET_TYPE_LINK()`) and the browser supports providing this information.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The link URL as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#EXTRA_CONTEXT_LINK_URL()` |   |

### getPageUrl

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable Uri getPageUrl()
```

Gets the URL of the current web page in the Custom Tab when the action was triggered. This is retrieved from `https://developer.android.com/reference/android/content/Intent.html#getData()`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | The current URL as a `https://developer.android.com/reference/android/net/Uri.html`, or `null` if not present or not applicable. |

### getTriggeredActionId

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public int getTriggeredActionId()
```

Gets the ID of the specific `https://developer.android.com/reference/androidx/browser/customtabs/CustomContentAction` that was triggered by the user.

| Returns |
|---|---|
| `int` | The integer ID of the triggered action. Returns -1 if the extra is not present, indicating an issue or that the ID was not properly sent. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent#EXTRA_TRIGGERED_CUSTOM_CONTENT_ACTION_ID()` |   |