PostMessageServiceConnection

abstract class PostMessageServiceConnection : ServiceConnection


A ServiceConnection for Custom Tabs providers to use while connecting to a PostMessageService on the client side. TODO(peconn): Make this not abstract with API change.

Summary

Public constructors

Public functions

Boolean

Binds the browser side to the client app through the given PostMessageService name.

Boolean

Records that the message channel has been created and notifies the client.

Unit

Called when the PostMessageService connection is established.

Unit

Called when the connection is lost with the PostMessageService.

Unit
Unit
Boolean
postMessage(message: String, extras: Bundle?)

Posts a message to the client.

Unit

Unbinds this service connection from the given context.

Public constructors

PostMessageServiceConnection

Added in 1.2.0
PostMessageServiceConnection(session: CustomTabsSessionToken)

Public functions

bindSessionToPostMessageService

Added in 1.2.0
fun bindSessionToPostMessageService(context: Context, packageName: String): Boolean

Binds the browser side to the client app through the given PostMessageService name. After this, this PostMessageServiceConnection can be used for sending postMessage related communication back to the client.

Parameters
context: Context

A context to bind to the service.

packageName: String

The name of the package to be bound to.

Returns
Boolean

Whether the binding was successful.

notifyMessageChannelReady

Added in 1.2.0
fun notifyMessageChannelReady(extras: Bundle?): Boolean

Records that the message channel has been created and notifies the client. This method should be called when the browser binds to the client side PostMessageService and also readies a connection to the web frame.

Parameters
extras: Bundle?

Unused.

Returns
Boolean

Whether the notification was sent successfully.

onPostMessageServiceConnected

Added in 1.2.0
fun onPostMessageServiceConnected(): Unit

Called when the PostMessageService connection is established.

onPostMessageServiceDisconnected

Added in 1.2.0
fun onPostMessageServiceDisconnected(): Unit

Called when the connection is lost with the PostMessageService.

onServiceConnected

Added in 1.2.0
fun onServiceConnected(name: ComponentName, service: IBinder): Unit

onServiceDisconnected

Added in 1.2.0
fun onServiceDisconnected(name: ComponentName): Unit

postMessage

Added in 1.2.0
fun postMessage(message: String, extras: Bundle?): Boolean

Posts a message to the client. This should be called when a tab controlled by related CustomTabsSession has sent a postMessage. If postMessage() is called from a single thread, then the messages will be posted in the same order.

Parameters
message: String

The message sent.

extras: Bundle?

Reserved for future use.

Returns
Boolean

Whether the postMessage was sent to the remote successfully.

unbindFromContext

Added in 1.2.0
fun unbindFromContext(context: Context): Unit

Unbinds this service connection from the given context.

Parameters
context: Context

The context to be unbound from.