The Android Developer Challenge is back! Submit your idea before December 2.

PostMessageServiceConnection

abstract class PostMessageServiceConnection : PostMessageBackend, ServiceConnection
kotlin.Any
   ↳ androidx.browser.customtabs.PostMessageServiceConnection

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 methods

open Boolean
bindSessionToPostMessageService(context: Context!, packageName: String!)

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.

open Unit

Called when the PostMessageService connection is established.

open Unit

Called when the connection is lost with the PostMessageService.

Unit

Unit

Boolean
postMessage(message: String!, extras: Bundle!)

Posts a message to the client.

open Unit

Unbinds this service connection from the given context.

Public constructors

<init>

PostMessageServiceConnection(session: CustomTabsSessionToken!)

Public methods

bindSessionToPostMessageService

open 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 Context!: The name of the package to be bound to.
Return
Boolean: Whether the binding was successful.

notifyMessageChannelReady

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.
Return
Boolean: Whether the notification was sent successfully.

onPostMessageServiceConnected

open fun onPostMessageServiceConnected(): Unit

Called when the PostMessageService connection is established.

onPostMessageServiceDisconnected

open fun onPostMessageServiceDisconnected(): Unit

Called when the connection is lost with the PostMessageService.

onServiceConnected

fun onServiceConnected(name: ComponentName!, service: IBinder!): Unit

onServiceDisconnected

fun onServiceDisconnected(name: ComponentName!): Unit

postMessage

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 String!: Reserved for future use.
Return
Boolean: Whether the postMessage was sent to the remote successfully.

unbindFromContext

open fun unbindFromContext(context: Context!): Unit

Unbinds this service connection from the given context.

Parameters
context Context!: The context to be unbound from.