# CustomTabsSession

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:customtabs:28.0.0-alpha1  
Summary:[Methods](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#)  

# CustomTabsSession

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
CustomTabsSession
`  
`

extends Object


``


`

|---|----------------------------------------------|
| java.lang.Object                                ||
| ↳ | android.support.customtabs.CustomTabsSession |

<br />

*** ** * ** ***

A class to be used for Custom Tabs related communication. Clients that want to launch Custom Tabs can use this class exclusively to handle all related communication.

## Summary

|                                                                                                                                                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                                                                                                                                                         ||
|---------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[CustomTabsSession](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession) | ` `[createMockSessionForTesting](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#createMockSessionForTesting(android.content.ComponentName))`(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` componentName) ` Provides browsers a way to generate a mock[CustomTabsSession](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession)for testing purposes.                                                                                                                                    |
| ` boolean`                                                                                                          | ` `[mayLaunchUrl](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#mayLaunchUrl(android.net.Uri, android.os.Bundle, java.util.List<android.os.Bundle>))`(`[Uri](https://developer.android.com/reference/android/net/Uri.html)` url, `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` extras, List<`[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`> otherLikelyBundles) ` Tells the browser of a likely future navigation to a URL.                                                                                   |
| ` int`                                                                                                              | ` `[postMessage](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#postMessage(java.lang.String, android.os.Bundle))`(String message, `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` extras) ` Sends a postMessage request using the origin communicated via[requestPostMessageChannel(CustomTabsSessionToken, Uri)](https://developer.android.com/reference/android/support/customtabs/CustomTabsService#requestPostMessageChannel(android.support.customtabs.CustomTabsSessionToken, android.net.Uri)).                                      |
| ` boolean`                                                                                                          | ` `[requestPostMessageChannel](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#requestPostMessageChannel(android.net.Uri))`(`[Uri](https://developer.android.com/reference/android/net/Uri.html)` postMessageOrigin) ` Sends a request to create a two way postMessage channel between the client and the browser.                                                                                                                                                                                                                                                       |
| ` boolean`                                                                                                          | ` `[setActionButton](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#setActionButton(android.graphics.Bitmap, java.lang.String))`(`[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)` icon, String description) ` This sets the action button on the toolbar with ID[TOOLBAR_ACTION_BUTTON_ID](https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent#TOOLBAR_ACTION_BUTTON_ID).                                                                                                                               |
| ` boolean`                                                                                                          | ` `[setSecondaryToolbarViews](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#setSecondaryToolbarViews(android.widget.RemoteViews, int[], android.app.PendingIntent))`(`[RemoteViews](https://developer.android.com/reference/android/widget/RemoteViews.html)` remoteViews, int[] clickableIDs, `[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)` pendingIntent) ` Updates the[RemoteViews](https://developer.android.com/reference/android/widget/RemoteViews.html)of the secondary toolbar in an existing custom tab session. |
| ` boolean`                                                                                                          | ` `[setToolbarItem](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#setToolbarItem(int, android.graphics.Bitmap, java.lang.String))`(int id, `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)` icon, String description) ` *This method was deprecated in API level 25.1.0. Use CustomTabsSession#setSecondaryToolbarViews(RemoteViews, int\[\], PendingIntent)*                                                                                                                                                                          |
| ` boolean`                                                                                                          | ` `[validateRelationship](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#validateRelationship(int, android.net.Uri, android.os.Bundle))`(int relation, `[Uri](https://developer.android.com/reference/android/net/Uri.html)` origin, `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` extras) ` Requests to validate a relationship between the application and an origin.                                                                                                                                                                    |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public methods

### createMockSessionForTesting

added in[version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
CustomTabsSession createMockSessionForTesting (ComponentName componentName)
```

Provides browsers a way to generate a mock[CustomTabsSession](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession)for testing purposes.

<br />

|                                        Parameters                                         ||
|-----------------|--------------------------------------------------------------------------|
| `componentName` | `ComponentName`: The component the session should be created for. <br /> |

|                                                                         Returns                                                                         ||
|-----------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [CustomTabsSession](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession) | A mock session with no functionality. <br /> |

### mayLaunchUrl

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean mayLaunchUrl (Uri url, 
                Bundle extras, 
                List<Bundle> otherLikelyBundles)
```

Tells the browser of a likely future navigation to a URL. The most likely URL has to be specified first. Optionally, a list of other likely URLs can be provided. They are treated as less likely than the first one, and have to be sorted in decreasing priority order. These additional URLs may be ignored. All previous calls to this method will be deprioritized.

<br />

|                                                                                                                                                                                                                                                   Parameters                                                                                                                                                                                                                                                    ||
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `url`                | `Uri`: Most likely URL. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `extras`             | `Bundle`: Reserved for future use. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `otherLikelyBundles` | `List`: Other likely destinations, sorted in decreasing likelihood order. Inside each Bundle, the client should provide a[Uri](https://developer.android.com/reference/android/net/Uri.html)using[KEY_URL](https://developer.android.com/reference/android/support/customtabs/CustomTabsService#KEY_URL)with[putParcelable(String, android.os.Parcelable)](https://developer.android.com/reference/android/os/Bundle.html#putParcelable(java.lang.String, android.os.Parcelable)). <br /> |

|               Returns               ||
|-----------|--------------------------|
| `boolean` | true for success. <br /> |

### postMessage

added in[version 25.4.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int postMessage (String message, 
                Bundle extras)
```

Sends a postMessage request using the origin communicated via[requestPostMessageChannel(CustomTabsSessionToken, Uri)](https://developer.android.com/reference/android/support/customtabs/CustomTabsService#requestPostMessageChannel(android.support.customtabs.CustomTabsSessionToken, android.net.Uri)). Fails when called before[notifyMessageChannelReady(Bundle)](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#notifyMessageChannelReady(android.os.Bundle))is received on the client side.

<br />

|                         Parameters                          ||
|-----------|--------------------------------------------------|
| `message` | `String`: The message that is being sent. <br /> |
| `extras`  | `Bundle`: Reserved for future use. <br />        |

|                                                                                                        Returns                                                                                                         ||
|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | An integer constant about the postMessage request result. Will return[RESULT_SUCCESS](https://developer.android.com/reference/android/support/customtabs/CustomTabsService#RESULT_SUCCESS)if successful. <br /> |

### requestPostMessageChannel

added in[version 25.4.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean requestPostMessageChannel (Uri postMessageOrigin)
```

Sends a request to create a two way postMessage channel between the client and the browser.

<br />

|                                                             Parameters                                                              ||
|---------------------|----------------------------------------------------------------------------------------------------------------|
| `postMessageOrigin` | `Uri`: A origin that the client is requesting to be identified as during the postMessage communication. <br /> |

|                                                                                       Returns                                                                                        ||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `boolean` | Whether the implementation accepted the request. Note that returning true here doesn't mean an origin has already been assigned as the validation is asynchronous. <br /> |

### setActionButton

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean setActionButton (Bitmap icon, 
                String description)
```

This sets the action button on the toolbar with ID[TOOLBAR_ACTION_BUTTON_ID](https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent#TOOLBAR_ACTION_BUTTON_ID).

<br />

|                                Parameters                                 ||
|---------------|------------------------------------------------------------|
| `icon`        | `Bitmap`: The new icon of the action button. <br />        |
| `description` | `String`: Content description of the action button. <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

**See also:**

- [setToolbarItem(int, Bitmap, String)](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession#setToolbarItem(int, android.graphics.Bitmap, java.lang.String))  

### setSecondaryToolbarViews

added in[version 25.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean setSecondaryToolbarViews (RemoteViews remoteViews, 
                int[] clickableIDs, 
                PendingIntent pendingIntent)
```

Updates the[RemoteViews](https://developer.android.com/reference/android/widget/RemoteViews.html)of the secondary toolbar in an existing custom tab session.

<br />

|                                                                                                                                   Parameters                                                                                                                                    ||
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `remoteViews`   | `RemoteViews`: The updated[RemoteViews](https://developer.android.com/reference/android/widget/RemoteViews.html)that will be shown in secondary toolbar. If null, the current secondary toolbar will be dismissed. <br />                                      |
| `clickableIDs`  | `int`: The ids of clickable views. The onClick event of these views will be handled by custom tabs. <br />                                                                                                                                                     |
| `pendingIntent` | `PendingIntent`: The[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)that will be sent when the user clicks on one of the[View](https://developer.android.com/reference/android/view/View.html)s in clickableIDs. <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### setToolbarItem

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean setToolbarItem (int id, 
                Bitmap icon, 
                String description)
```

<br />

**This method was deprecated in API level 25.1.0.**   
Use CustomTabsSession#setSecondaryToolbarViews(RemoteViews, int\[\], PendingIntent)

Updates the visuals for toolbar items. Will only succeed if a custom tab created using this session is in the foreground in browser and the given id is valid.

<br />

|                                Parameters                                ||
|---------------|-----------------------------------------------------------|
| `id`          | `int`: The id for the item to update. <br />              |
| `icon`        | `Bitmap`: The new icon of the toolbar item. <br />        |
| `description` | `String`: Content description of the toolbar item. <br /> |

|                     Returns                     ||
|-----------|--------------------------------------|
| `boolean` | Whether the update succeeded. <br /> |

### validateRelationship

added in[version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean validateRelationship (int relation, 
                Uri origin, 
                Bundle extras)
```

Requests to validate a relationship between the application and an origin.

See[here](https://developers.google.com/digital-asset-links/v1/getting-started)for documentation about Digital Asset Links. This methods requests the browser to verify a relation with the calling application, to grant the associated rights.

If this method returns`true`, the validation result will be provided through[onRelationshipValidationResult(int, Uri, boolean, Bundle)](https://developer.android.com/reference/android/support/customtabs/CustomTabsCallback#onRelationshipValidationResult(int, android.net.Uri, boolean, android.os.Bundle)). Otherwise the request didn't succeed. The client must call[warmup(long)](https://developer.android.com/reference/android/support/customtabs/CustomTabsClient#warmup(long))before this.

<br />

|                                                Parameters                                                ||
|------------|----------------------------------------------------------------------------------------------|
| `relation` | `int`: Relation to check, must be one of the`CustomTabsService#RELATION_* `constants. <br /> |
| `origin`   | `Uri`: Origin. <br />                                                                        |
| `extras`   | `Bundle`: Reserved for future use. <br />                                                    |

|                                 Returns                                 ||
|-----------|--------------------------------------------------------------|
| `boolean` | `true`if the request has been submitted successfully. <br /> |

-

  ## Annotations

  - [CustomTabsService.Relation](https://developer.android.com/reference/android/support/customtabs/CustomTabsService.Relation)
  - [CustomTabsService.Result](https://developer.android.com/reference/android/support/customtabs/CustomTabsService.Result)
-

  ## Classes

  - [CustomTabsCallback](https://developer.android.com/reference/android/support/customtabs/CustomTabsCallback)
  - [CustomTabsClient](https://developer.android.com/reference/android/support/customtabs/CustomTabsClient)
  - [CustomTabsIntent](https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent)
  - [CustomTabsIntent.Builder](https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent.Builder)
  - [CustomTabsService](https://developer.android.com/reference/android/support/customtabs/CustomTabsService)
  - [CustomTabsServiceConnection](https://developer.android.com/reference/android/support/customtabs/CustomTabsServiceConnection)
  - [CustomTabsSession](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession)
  - [CustomTabsSessionToken](https://developer.android.com/reference/android/support/customtabs/CustomTabsSessionToken)
  - [PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService)
  - [PostMessageServiceConnection](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection)
  - [R](https://developer.android.com/reference/android/support/customtabs/R)
  - [R.anim](https://developer.android.com/reference/android/support/customtabs/R.anim)
  - [R.attr](https://developer.android.com/reference/android/support/customtabs/R.attr)
  - [R.bool](https://developer.android.com/reference/android/support/customtabs/R.bool)
  - [R.color](https://developer.android.com/reference/android/support/customtabs/R.color)
  - [R.dimen](https://developer.android.com/reference/android/support/customtabs/R.dimen)
  - [R.drawable](https://developer.android.com/reference/android/support/customtabs/R.drawable)
  - [R.id](https://developer.android.com/reference/android/support/customtabs/R.id)
  - [R.integer](https://developer.android.com/reference/android/support/customtabs/R.integer)
  - [R.layout](https://developer.android.com/reference/android/support/customtabs/R.layout)
  - [R.string](https://developer.android.com/reference/android/support/customtabs/R.string)
  - [R.style](https://developer.android.com/reference/android/support/customtabs/R.style)
  - [R.styleable](https://developer.android.com/reference/android/support/customtabs/R.styleable)
  - [TrustedWebUtils](https://developer.android.com/reference/android/support/customtabs/TrustedWebUtils)