PostMessageServiceConnection

public abstract class PostMessageServiceConnection implements 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 methods

boolean
bindSessionToPostMessageService(
    @NonNull Context context,
    @NonNull String packageName
)

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

final boolean

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

void

Called when the PostMessageService connection is established.

void

Called when the connection is lost with the PostMessageService.

final void
final void
final boolean
postMessage(@NonNull String message, @Nullable Bundle extras)

Posts a message to the client.

void

Unbinds this service connection from the given context.

Public constructors

PostMessageServiceConnection

Added in 1.2.0
public PostMessageServiceConnection(@NonNull CustomTabsSessionToken session)

Public methods

bindSessionToPostMessageService

Added in 1.2.0
public boolean bindSessionToPostMessageService(
    @NonNull Context context,
    @NonNull String packageName
)

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
@NonNull Context context

A context to bind to the service.

@NonNull String packageName

The name of the package to be bound to.

Returns
boolean

Whether the binding was successful.

notifyMessageChannelReady

Added in 1.2.0
public final boolean notifyMessageChannelReady(@Nullable Bundle extras)

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
@Nullable Bundle extras

Unused.

Returns
boolean

Whether the notification was sent successfully.

onPostMessageServiceConnected

Added in 1.2.0
public void onPostMessageServiceConnected()

Called when the PostMessageService connection is established.

onPostMessageServiceDisconnected

Added in 1.2.0
public void onPostMessageServiceDisconnected()

Called when the connection is lost with the PostMessageService.

onServiceConnected

Added in 1.2.0
public final void onServiceConnected(@NonNull ComponentName name, @NonNull IBinder service)

onServiceDisconnected

Added in 1.2.0
public final void onServiceDisconnected(@NonNull ComponentName name)

postMessage

Added in 1.2.0
public final boolean postMessage(@NonNull String message, @Nullable Bundle extras)

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
@NonNull String message

The message sent.

@Nullable Bundle extras

Reserved for future use.

Returns
boolean

Whether the postMessage was sent to the remote successfully.

unbindFromContext

Added in 1.2.0
public void unbindFromContext(@NonNull Context context)

Unbinds this service connection from the given context.

Parameters
@NonNull Context context

The context to be unbound from.