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 |
TYPE_STRING = 0Indicates the payload of WebMessageCompat is String. |
Public constructors |
|---|
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Creates a WebMessage with JavaScript ArrayBuffer payload. |
WebMessageCompat(data: String?)Creates a WebMessage with String payload. |
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Creates a WebMessage with JavaScript ArrayBuffer payload. |
WebMessageCompat(data: String?, ports: Array<WebMessagePortCompat!>?)Creates a WebMessage with String payload. |
Public functions |
|
|---|---|
ByteArray<Byte> |
Returns the ArrayBuffer data of message. |
String? |
getData()Returns the String data of the message. |
Array<WebMessagePortCompat!>? |
getPorts()Returns the ports that are sent with the message, or |
Int |
getType()Returns the payload type of the message. |
Constants
TYPE_ARRAY_BUFFER
const val TYPE_ARRAY_BUFFER = 1: Int
Indicates the payload of WebMessageCompat is JavaScript ArrayBuffer.
TYPE_STRING
const val TYPE_STRING = 0: Int
Indicates the payload of WebMessageCompat is String.
Public constructors
WebMessageCompat
@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
WebMessageCompat(data: String?)
Creates a WebMessage with String payload.
| Parameters | |
|---|---|
data: String? |
the string of the message. |
WebMessageCompat
@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
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
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. }
getData
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
fun getPorts(): Array<WebMessagePortCompat!>?
Returns the ports that are sent with the message, or null if no port is sent.