WebMessageCompat

class WebMessageCompat


The Java representation of the HTML5 PostMessage event. See https://html.spec.whatwg.org/multipage/comms.html#the-messageevent-interfaces for definition of a MessageEvent in HTML5.

Summary

Constants

const Int

Indicates the payload of WebMessageCompat is JavaScript ArrayBuffer.

const Int

Indicates the payload of WebMessageCompat is String.

Public constructors

@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
WebMessageCompat(arrayBuffer: ByteArray)

Creates a WebMessage with JavaScript ArrayBuffer payload.

Creates a WebMessage with String payload.

@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
WebMessageCompat(
    arrayBuffer: ByteArray,
    ports: Array<WebMessagePortCompat!>?
)

Creates a WebMessage with JavaScript ArrayBuffer payload.

Creates a WebMessage with String payload.

Public functions

ByteArray<Byte>

Returns the ArrayBuffer data of message.

String?

Returns the String data of the message.

Array<WebMessagePortCompat!>?

Returns the ports that are sent with the message, or null if no port is sent.

Int

Returns the payload type of the message.

Constants

TYPE_ARRAY_BUFFER

Added in 1.8.0
const val TYPE_ARRAY_BUFFER = 1: Int

Indicates the payload of WebMessageCompat is JavaScript ArrayBuffer.

TYPE_STRING

Added in 1.8.0
const val TYPE_STRING = 0: Int

Indicates the payload of WebMessageCompat is String.

Public constructors

WebMessageCompat

Added in 1.8.0
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
WebMessageCompat(arrayBuffer: ByteArray)

Creates a WebMessage with JavaScript ArrayBuffer payload.

Parameters
arrayBuffer: ByteArray

the array buffer data of the message.

WebMessageCompat

Added in 1.1.0
WebMessageCompat(data: String?)

Creates a WebMessage with String payload.

Parameters
data: String?

the string of the message.

WebMessageCompat

Added in 1.8.0
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
WebMessageCompat(
    arrayBuffer: ByteArray,
    ports: Array<WebMessagePortCompat!>?
)

Creates a WebMessage with JavaScript ArrayBuffer payload.

Parameters
arrayBuffer: ByteArray

the array buffer data of the message.

ports: Array<WebMessagePortCompat!>?

the ports that are sent with the message.

WebMessageCompat

Added in 1.1.0
WebMessageCompat(data: String?, ports: Array<WebMessagePortCompat!>?)

Creates a WebMessage with String payload.

Parameters
data: String?

the string data of the message.

ports: Array<WebMessagePortCompat!>?

the ports that are sent with the message.

Public functions

getArrayBuffer

Added in 1.8.0
fun getArrayBuffer(): ByteArray<Byte>

Returns the ArrayBuffer data of message. A ArrayBuffer or Transferable ArrayBuffer can be received from JavaScript. This should only be called when getType returns TYPE_ARRAY_BUFFER. Example:

WebMessageCompat message = ... // The WebMessageCompat received or prepared.
if (message.getType() == WebMessageCompat.TYPE_ARRAY_BUFFER) {
    byte[] arrayBuffer = message.getArrayBuffer();
    // Access arrayBuffer data here.
}
Returns
ByteArray<Byte>

ArrayBuffer payload data.

getData

Added in 1.1.0
fun getData(): String?

Returns the String data of the message. This should only be called when getType returns TYPE_STRING. Example:

WebMessageCompat message = ... // The WebMessageCompat received or prepared.
if (message.getType() == WebMessageCompat.TYPE_STRING) {
    String string = message.getData();
    // Access string data here.
}
Returns
String?

String payload data.

getPorts

Added in 1.1.0
fun getPorts(): Array<WebMessagePortCompat!>?

Returns the ports that are sent with the message, or null if no port is sent.

getType

Added in 1.8.0
fun getType(): Int

Returns the payload type of the message.

Returns
Int

the payload type of WebMessageCompat.