# 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
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/kotlin/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 functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ContentActionSelectedData?` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ContentActionSelectedData#fromIntent(android.content.Intent)(intent: https://developer.android.com/reference/android/content/Intent.html?)` Creates a `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ContentActionSelectedData` instance from the given `https://developer.android.com/reference/android/content/Intent.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ContentActionSelectedData#getImageAltText()()` Gets the alt text of the clicked element (e.g., an image or link), if available. |
| `https://developer.android.com/reference/android/net/Uri.html?` | `https://developer.android.com/reference/kotlin/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://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/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://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/kotlin/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://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/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://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/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/kotlin/androidx/browser/customtabs/ContentActionSelectedData#getClickedContentTargetType()` returns `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsIntent#CONTENT_TARGET_TYPE_LINK()`) and the browser supports providing this information. |
| `https://developer.android.com/reference/android/net/Uri.html?` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ContentActionSelectedData#getPageUrl()()` Gets the URL of the current web page in the Custom Tab when the action was triggered. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ContentActionSelectedData#getTriggeredActionId()()` Gets the ID of the specific `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomContentAction` that was triggered by the user. |

## Public functions

### fromIntent

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

```
java-static fun fromIntent(intent: Intent?): ContentActionSelectedData?
```

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

| Parameters |
|---|---|
| `intent: https://developer.android.com/reference/android/content/Intent.html?` | The intent received from the browser's custom content action. This intent is expected to contain the relevant extras. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ContentActionSelectedData?` | A `https://developer.android.com/reference/kotlin/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)

```
fun getClickedContentTargetType(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsIntent.ContentTargetType` integer value (e.g., `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsIntent#CONTENT_TARGET_TYPE_IMAGE()`, `https://developer.android.com/reference/kotlin/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/kotlin/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)

```
fun getImageAltText(): String?
```

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://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The alt text as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
fun getImageDataUri(): Uri?
```

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://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/kotlin/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)

```
fun getImageUrl(): String?
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The image URL as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
fun getIntent(): Intent
```

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://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)

```
fun getLinkText(): String?
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The link text as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
fun getLinkUrl(): String?
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The link URL as a String, or `null` if not present or not applicable. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
fun getPageUrl(): Uri?
```

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://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)

```
fun getTriggeredActionId(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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/kotlin/androidx/browser/customtabs/CustomTabsIntent#EXTRA_TRIGGERED_CUSTOM_CONTENT_ACTION_ID()` |   |