ContentActionSelectedData


@ExperimentalCustomContentAction
class ContentActionSelectedData


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 addCustomContentAction, the browser sends the android.app.PendingIntent associated with the selected action when the user triggers it. The browser includes specific extras in the Intent carried by the android.app.PendingIntent. 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 ContentActionSelectedData?
fromIntent(intent: Intent?)

Creates a ContentActionSelectedData instance from the given Intent.

Int

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

String?

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

Uri?

Gets a Uri pointing to the data of the clicked image, if the interacted element was an image and the browser supports providing this information.

String?

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

Intent

Returns the underlying Intent object that this data was parsed from.

String?

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

String?

Gets the URL of the clicked link, if the interacted element was a link (i.e., getClickedContentTargetType returns CONTENT_TARGET_TYPE_LINK) and the browser supports providing this information.

Uri

Gets the URL of the current web page in the Custom Tab when the action was triggered.

Int

Gets the ID of the specific CustomContentAction that was triggered by the user.

Public functions

fromIntent

Added in 1.9.0-rc01
java-static fun fromIntent(intent: Intent?): ContentActionSelectedData?

Creates a ContentActionSelectedData instance from the given Intent.

Parameters
intent: Intent?

The intent received from the browser's custom content action. This intent is expected to contain the relevant extras.

Returns
ContentActionSelectedData?

A ContentActionSelectedData instance, or null if the provided intent is null.

getClickedContentTargetType

Added in 1.9.0-rc01
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
Int

The CustomTabsIntent.ContentTargetType integer value (e.g., CONTENT_TARGET_TYPE_IMAGE, 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.

getImageAltText

Added in 1.9.0-rc01
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
String?

The alt text as a String, or null if not present or not applicable.

getImageDataUri

Added in 1.9.0-rc01
fun getImageDataUri(): Uri?

Gets a Uri 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
Uri?

A Uri for the image data, or null if not present or Android version is below Tiramisu.

getImageUrl

Added in 1.9.0-rc01
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
String?

The image URL as a String, or null if not present or not applicable.

getIntent

Added in 1.9.0-rc01
fun getIntent(): Intent

Returns the underlying Intent 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
Intent

The original Intent.

getLinkText

Added in 1.9.0-rc01
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
String?

The link text as a String, or null if not present or not applicable.

getLinkUrl

Added in 1.9.0-rc01
fun getLinkUrl(): String?

Gets the URL of the clicked link, if the interacted element was a link (i.e., getClickedContentTargetType returns CONTENT_TARGET_TYPE_LINK) and the browser supports providing this information.

Returns
String?

The link URL as a String, or null if not present or not applicable.

getPageUrl

Added in 1.9.0-rc01
fun getPageUrl(): Uri

Gets the URL of the current web page in the Custom Tab when the action was triggered. This is retrieved from getData.

Returns
Uri

The current URL as a Uri.

getTriggeredActionId

Added in 1.9.0-rc01
fun getTriggeredActionId(): Int

Gets the ID of the specific 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.