# CustomTabsCallback

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

*** ** * ** ***


```
class CustomTabsCallback
```

<br />

*** ** * ** ***

A callback class for custom tabs client to get messages regarding events in their custom tabs. In the implementation, all callbacks are sent to the UI thread for the client.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET() = 1` The activity is being displayed as a bottom-sheet at its initial height. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET_MAXIMIZED() = 2` The activity is being displayed as a bottom-sheet at its maximized height. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#ACTIVITY_LAYOUT_STATE_FULL_SCREEN() = 5` The activity is being displayed over the whole window. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#ACTIVITY_LAYOUT_STATE_SIDE_SHEET() = 3` The activity is being displayed as a side-sheet at its initial width. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#ACTIVITY_LAYOUT_STATE_SIDE_SHEET_MAXIMIZED() = 4` The activity is being displayed as a side-sheet at its maximized width. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#ACTIVITY_LAYOUT_STATE_UNKNOWN() = 0` The activity's layout state is unknown. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#NAVIGATION_ABORTED() = 4` Sent when loading was aborted by a user action before it finishes like clicking on a link or refreshing the page. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#NAVIGATION_FAILED() = 3` Sent when the tab couldn't finish loading due to a failure. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#NAVIGATION_FINISHED() = 2` Sent when the tab has finished loading a page. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#NAVIGATION_STARTED() = 1` Sent when the tab has started loading a page. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#TAB_HIDDEN() = 6` Sent when the tab becomes hidden. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#TAB_SHOWN() = 5` Sent when the tab becomes visible. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#CustomTabsCallback()()` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#extraCallback(java.lang.String,android.os.Bundle)(callbackName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` Unsupported callbacks that may be provided by the implementation. |
| `https://developer.android.com/reference/android/os/Bundle.html?` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#extraCallbackWithResult(java.lang.String,android.os.Bundle)(callbackName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` The same as `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#extraCallback(java.lang.String,android.os.Bundle)`, except that this method allows the custom tabs provider to return a result. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onActivityLayout(int,int,int,int,int,android.os.Bundle)( left: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, top: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, right: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, state: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, extras: https://developer.android.com/reference/android/os/Bundle.html )` Called when the Partial Custom Tab's layout has changed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onActivityResized(int,int,android.os.Bundle)( height: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, width: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, extras: https://developer.android.com/reference/android/os/Bundle.html )` Called when the tab is resized. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onMessageChannelReady(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html?)` Called when `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsSession` has requested a postMessage channel through `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsService#requestPostMessageChannel(androidx.browser.customtabs.CustomTabsSessionToken,android.net.Uri)` and the channel is ready for sending and receiving messages on both ends. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onMinimized(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html)` Called when the Custom Tab is minimized by the user such that it covers a small part of the screen. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onNavigationEvent(int,android.os.Bundle)(navigationEvent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, extras: https://developer.android.com/reference/android/os/Bundle.html?)` To be called when a navigation event happens. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onPostMessage(java.lang.String,android.os.Bundle)(message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, extras: https://developer.android.com/reference/android/os/Bundle.html?)` Called when a tab controlled by this `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsSession` has sent a postMessage. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onRelationshipValidationResult(int,android.net.Uri,boolean,android.os.Bundle)( @https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsService.Relation relation: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, requestedOrigin: https://developer.android.com/reference/android/net/Uri.html, result: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, extras: https://developer.android.com/reference/android/os/Bundle.html? )` Called when a relationship validation result is available. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onUnminimized(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html)` Called when the Custom Tab is unminimized by the user such that it returns back to its original state. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#onWarmupCompleted(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html)` Called when the browser process finished warming up initiated by warmup. |

## Constants

### ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET

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

```
const val ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET = 1: Int
```

The activity is being displayed as a bottom-sheet at its initial height.

### ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET_MAXIMIZED

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

```
const val ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET_MAXIMIZED = 2: Int
```

The activity is being displayed as a bottom-sheet at its maximized height.

### ACTIVITY_LAYOUT_STATE_FULL_SCREEN

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

```
const val ACTIVITY_LAYOUT_STATE_FULL_SCREEN = 5: Int
```

The activity is being displayed over the whole window. This will be the case when a Partial Custom Tab bottom sheet or side sheet cannot be displayed due to minimum width restrictions (see `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsIntent#EXTRA_INITIAL_ACTIVITY_WIDTH_PX()`) or browser limitations.

### ACTIVITY_LAYOUT_STATE_SIDE_SHEET

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

```
const val ACTIVITY_LAYOUT_STATE_SIDE_SHEET = 3: Int
```

The activity is being displayed as a side-sheet at its initial width.

### ACTIVITY_LAYOUT_STATE_SIDE_SHEET_MAXIMIZED

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

```
const val ACTIVITY_LAYOUT_STATE_SIDE_SHEET_MAXIMIZED = 4: Int
```

The activity is being displayed as a side-sheet at its maximized width.

### ACTIVITY_LAYOUT_STATE_UNKNOWN

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

```
const val ACTIVITY_LAYOUT_STATE_UNKNOWN = 0: Int
```

The activity's layout state is unknown. This value communicates an error state, the fact that the state cannot be determined, or that the browser implementation does not provide support for this feature.

### NAVIGATION_ABORTED

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

```
const val NAVIGATION_ABORTED = 4: Int
```

Sent when loading was aborted by a user action before it finishes like clicking on a link or refreshing the page.

### NAVIGATION_FAILED

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

```
const val NAVIGATION_FAILED = 3: Int
```

Sent when the tab couldn't finish loading due to a failure.

### NAVIGATION_FINISHED

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

```
const val NAVIGATION_FINISHED = 2: Int
```

Sent when the tab has finished loading a page.

### NAVIGATION_STARTED

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

```
const val NAVIGATION_STARTED = 1: Int
```

Sent when the tab has started loading a page.

### TAB_HIDDEN

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

```
const val TAB_HIDDEN = 6: Int
```

Sent when the tab becomes hidden.

### TAB_SHOWN

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

```
const val TAB_SHOWN = 5: Int
```

Sent when the tab becomes visible.

## Public constructors

### CustomTabsCallback

Added in 1.2.0

```
CustomTabsCallback()
```

## Public functions

### extraCallback

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

```
fun extraCallback(callbackName: String, args: Bundle?): Unit
```

Unsupported callbacks that may be provided by the implementation.

**Note:** Clients should **never** rely on this callback to be called and/or to have a defined behavior, as it is entirely implementation-defined and not supported.

This can be used by implementations to add extra callbacks, for testing or experimental purposes.

| Parameters |
|---|---|
| `callbackName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | Name of the extra callback. |
| `args: https://developer.android.com/reference/android/os/Bundle.html?` | Arguments for the callback |

### extraCallbackWithResult

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

```
fun extraCallbackWithResult(callbackName: String, args: Bundle?): Bundle?
```

The same as `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsCallback#extraCallback(java.lang.String,android.os.Bundle)`, except that this method allows the custom tabs provider to return a result. A return value of `null` will be used to signify that the client does not know how to handle the callback. As optional best practices, `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsService#KEY_SUCCESS()` could be use to identify that callback was \*successfully\* handled. For example, when returning a message with result:

```kotlin
    Bundle result = new Bundle();
    result.putString("message", message);
    if (success)
        result.putBoolean(CustomTabsService#KEY_SUCCESS, true);
    return result;
```
The caller side:

```kotlin
    Bundle result = extraCallbackWithResult(callbackName, args);
    if (result.getBoolean(CustomTabsService#KEY_SUCCESS)) {
        // callback was successfully handled
    }
```

### onActivityLayout

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

```
fun onActivityLayout(
    left: @Dimension(unit = 1) Int,
    top: @Dimension(unit = 1) Int,
    right: @Dimension(unit = 1) Int,
    bottom: @Dimension(unit = 1) Int,
    state: Int,
    extras: Bundle
): Unit
```

Called when the Partial Custom Tab's layout has changed. This callback is not applicable to Custom Tabs that are not launched with `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsIntent#EXTRA_INITIAL_ACTIVITY_WIDTH_PX()` or `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsIntent#EXTRA_INITIAL_ACTIVITY_HEIGHT_PX()` set to their intent.

| Parameters |
|---|---|
| `left: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The new left coordinate of the Partial Custom Tab's window in pixels. |
| `top: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The new top coordinate of the Partial Custom Tab's window in pixels. |
| `right: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The new right coordinate of the Partial Custom Tab's window in pixels. |
| `bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The new bottom coordinate of the Partial Custom Tab's window in pixels. |
| `state: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type of Partial Custom Tab that is currently displayed on the screen. |
| `extras: https://developer.android.com/reference/android/os/Bundle.html` | Reserved for future use. |

### onActivityResized

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

```
fun onActivityResized(
    height: @Dimension(unit = 1) Int,
    width: @Dimension(unit = 1) Int,
    extras: Bundle
): Unit
```

Called when the tab is resized.

| Parameters |
|---|---|
| `height: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The updated height in px. |
| `width: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The updated width in px. |
| `extras: https://developer.android.com/reference/android/os/Bundle.html` | Reserved for future use. |

### onMessageChannelReady

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

```
fun onMessageChannelReady(extras: Bundle?): Unit
```

Called when `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsSession` has requested a postMessage channel through `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsService#requestPostMessageChannel(androidx.browser.customtabs.CustomTabsSessionToken,android.net.Uri)` and the channel is ready for sending and receiving messages on both ends.

| Parameters |
|---|---|
| `extras: https://developer.android.com/reference/android/os/Bundle.html?` | Reserved for future use. |

### onMinimized

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

```
fun onMinimized(extras: Bundle): Unit
```

Called when the Custom Tab is minimized by the user such that it covers a small part of the screen.

| Parameters |
|---|---|
| `extras: https://developer.android.com/reference/android/os/Bundle.html` | Reserved for future use. |

### onNavigationEvent

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

```
fun onNavigationEvent(navigationEvent: Int, extras: Bundle?): Unit
```

To be called when a navigation event happens.

| Parameters |
|---|---|
| `navigationEvent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The code corresponding to the navigation event. |
| `extras: https://developer.android.com/reference/android/os/Bundle.html?` | Reserved for future use. |

### onPostMessage

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

```
fun onPostMessage(message: String, extras: Bundle?): Unit
```

Called when a tab controlled by this `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsSession` has sent a postMessage. If postMessage() is called from a single thread, then the messages will be posted in the same order. When received on the client side, it is the client's responsibility to preserve the ordering further.

| Parameters |
|---|---|
| `message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The message sent. |
| `extras: https://developer.android.com/reference/android/os/Bundle.html?` | Reserved for future use. |

### onRelationshipValidationResult

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

```
fun onRelationshipValidationResult(
    @CustomTabsService.Relation relation: Int,
    requestedOrigin: Uri,
    result: Boolean,
    extras: Bundle?
): Unit
```

Called when a relationship validation result is available.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsService.Relation relation: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Relation for which the result is available. Value previously passed to `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsSession#validateRelationship(int,android.net.Uri,android.os.Bundle)`. Must be one of the `CustomTabsService#RELATION_* ` constants. |
| `requestedOrigin: https://developer.android.com/reference/android/net/Uri.html` | Origin requested. Value previously passed to `https://developer.android.com/reference/kotlin/androidx/browser/customtabs/CustomTabsSession#validateRelationship(int,android.net.Uri,android.os.Bundle)`. |
| `result: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the relation was validated. |
| `extras: https://developer.android.com/reference/android/os/Bundle.html?` | Reserved for future use. |

### onUnminimized

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

```
fun onUnminimized(extras: Bundle): Unit
```

Called when the Custom Tab is unminimized by the user such that it returns back to its original state.

| Parameters |
|---|---|
| `extras: https://developer.android.com/reference/android/os/Bundle.html` | Reserved for future use. |

### onWarmupCompleted

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

```
fun onWarmupCompleted(extras: Bundle): Unit
```

Called when the browser process finished warming up initiated by warmup.

| Parameters |
|---|---|
| `extras: https://developer.android.com/reference/android/os/Bundle.html` | Reserved for future use. |