# PostMessageServiceConnection

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

# PostMessageServiceConnection

| 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


abstract
class
PostMessageServiceConnection
`  
`

extends Object


``


implements

`[ServiceConnection](https://developer.android.com/reference/android/content/ServiceConnection.html)`


`

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

<br />

*** ** * ** ***

A[ServiceConnection](https://developer.android.com/reference/android/content/ServiceConnection.html)for Custom Tabs providers to use while connecting to a[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService)on the client side.

## Summary

|                                                                                                                                                                 ### Public constructors                                                                                                                                                                 ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[PostMessageServiceConnection](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#PostMessageServiceConnection(android.support.customtabs.CustomTabsSessionToken))`(`[CustomTabsSessionToken](https://developer.android.com/reference/android/support/customtabs/CustomTabsSessionToken)` session) ` |

|                                                                                                                                                                                                                                                                                                  ### Public methods                                                                                                                                                                                                                                                                                                   ||
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`       | ` `[bindSessionToPostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#bindSessionToPostMessageService(android.content.Context, java.lang.String))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, String packageName) ` Binds the browser side to the client app through the given[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService)name.                                                                                       |
| ` final boolean` | ` `[notifyMessageChannelReady](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#notifyMessageChannelReady(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` extras) ` Notifies the client that the postMessage channel requested with[requestPostMessageChannel(CustomTabsSessionToken, android.net.Uri)](https://developer.android.com/reference/android/support/customtabs/CustomTabsService#requestPostMessageChannel(android.support.customtabs.CustomTabsSessionToken, android.net.Uri))is ready. |
| ` void`          | ` `[onPostMessageServiceConnected](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#onPostMessageServiceConnected())`() ` Called when the[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService)connection is established.                                                                                                                                                                                                                                                                       |
| ` void`          | ` `[onPostMessageServiceDisconnected](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#onPostMessageServiceDisconnected())`() ` Called when the connection is lost with the[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService).                                                                                                                                                                                                                                                              |
| ` final void`    | ` `[onServiceConnected](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#onServiceConnected(android.content.ComponentName, android.os.IBinder))`(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` name, `[IBinder](https://developer.android.com/reference/android/os/IBinder.html)` service) `                                                                                                                                                                                                         |
| ` final void`    | ` `[onServiceDisconnected](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#onServiceDisconnected(android.content.ComponentName))`(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` name) `                                                                                                                                                                                                                                                                                                             |
| ` final boolean` | ` `[postMessage](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#postMessage(java.lang.String, android.os.Bundle))`(String message, `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)` extras) ` Posts a message to the client.                                                                                                                                                                                                                                                                                             |
| ` void`          | ` `[unbindFromContext](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#unbindFromContext(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context) ` Unbinds this service connection from the given context.                                                                                                                                                                                                                                                                            |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#)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() `                    | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection#)From interface` `[android.content.ServiceConnection](https://developer.android.com/reference/android/content/ServiceConnection.html)` ` |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` default void`  | ` onBindingDied(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` arg0) `                                                                                         | | ` default void`  | ` onNullBinding(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` arg0) `                                                                                         | | ` abstract void` | ` onServiceConnected(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` arg0, `[IBinder](https://developer.android.com/reference/android/os/IBinder.html)` arg1) ` | | ` abstract void` | ` onServiceDisconnected(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)` arg0) `                                                                                 | ||

## Public constructors

### PostMessageServiceConnection

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

```
PostMessageServiceConnection (CustomTabsSessionToken session)
```

<br />

<br />

|                 Parameters                 ||
|-----------|---------------------------------|
| `session` | `CustomTabsSessionToken` <br /> |

## Public methods

### bindSessionToPostMessageService

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

```
boolean bindSessionToPostMessageService (Context context, 
                String packageName)
```

Binds the browser side to the client app through the given[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService)name. After this, this[PostMessageServiceConnection](https://developer.android.com/reference/android/support/customtabs/PostMessageServiceConnection)can be used for sending postMessage related communication back to the client.

<br />

|                               Parameters                                ||
|---------------|----------------------------------------------------------|
| `context`     | `Context`: A context to bind to the service. <br />      |
| `packageName` | `String`: The name of the package to be bound to. <br /> |

|                        Returns                        ||
|-----------|--------------------------------------------|
| `boolean` | Whether the binding was successful. <br /> |

### notifyMessageChannelReady

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

```
boolean notifyMessageChannelReady (Bundle extras)
```

Notifies the client that the postMessage channel requested with[requestPostMessageChannel(CustomTabsSessionToken, android.net.Uri)](https://developer.android.com/reference/android/support/customtabs/CustomTabsService#requestPostMessageChannel(android.support.customtabs.CustomTabsSessionToken, android.net.Uri))is ready. This method should be called when the browser binds to the client side[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService)and also readies a connection to the web frame.

<br />

|                     Parameters                      ||
|----------|-------------------------------------------|
| `extras` | `Bundle`: Reserved for future use. <br /> |

|                                     Returns                                     ||
|-----------|----------------------------------------------------------------------|
| `boolean` | Whether the notification was sent to the remote successfully. <br /> |

### onPostMessageServiceConnected

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

```
void onPostMessageServiceConnected ()
```

Called when the[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService)connection is established.

<br />

### onPostMessageServiceDisconnected

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

```
void onPostMessageServiceDisconnected ()
```

Called when the connection is lost with the[PostMessageService](https://developer.android.com/reference/android/support/customtabs/PostMessageService).

<br />

### onServiceConnected

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

```
void onServiceConnected (ComponentName name, 
                IBinder service)
```

<br />

<br />

|            Parameters             ||
|-----------|------------------------|
| `name`    | `ComponentName` <br /> |
| `service` | `IBinder` <br />       |

### onServiceDisconnected

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

```
void onServiceDisconnected (ComponentName name)
```

<br />

<br />

|           Parameters           ||
|--------|------------------------|
| `name` | `ComponentName` <br /> |

### postMessage

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

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

Posts a message to the client. This should be called when a tab controlled by related[CustomTabsSession](https://developer.android.com/reference/android/support/customtabs/CustomTabsSession)has sent a postMessage. If postMessage() is called from a single thread, then the messages will be posted in the same order.

<br />

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

|                                    Returns                                     ||
|-----------|---------------------------------------------------------------------|
| `boolean` | Whether the postMessage was sent to the remote successfully. <br /> |

### unbindFromContext

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

```
void unbindFromContext (Context context)
```

Unbinds this service connection from the given context.

<br />

|                          Parameters                          ||
|-----------|---------------------------------------------------|
| `context` | `Context`: The context to be unbound from. <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)