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

<init>(@NonNull session: CustomTabsSessionToken)

Public methods

open Boolean
bindSessionToPostMessageService(@NonNull context: Context, @NonNull packageName: String)

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

Boolean
notifyMessageChannelReady(@Nullable extras: Bundle?)

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
onServiceConnected(@NonNull name: ComponentName, @NonNull service: IBinder)

Unit

Boolean
postMessage(@NonNull message: String, @Nullable extras: Bundle?)

Posts a message to the client.

open Unit
unbindFromContext(@NonNull context: Context)

Unbinds this service connection from the given context.

Public constructors

<init>

PostMessageServiceConnection(@NonNull session: CustomTabsSessionToken)

Public methods

bindSessionToPostMessageService

open fun bindSessionToPostMessageService(@NonNull context: Context, @NonNull 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(@Nullable 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(@NonNull name: ComponentName, @NonNull service: IBinder): Unit

onServiceDisconnected

fun onServiceDisconnected(@NonNull name: ComponentName): Unit

postMessage

fun postMessage(@NonNull message: String, @Nullable 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(@NonNull context: Context): Unit

Unbinds this service connection from the given context.

Parameters
context Context: The context to be unbound from.