Android 12 Developer Preview is here! Try it out, and give us your feedback!


public static abstract class WebMessagePortCompat.WebMessageCallbackCompat
extends Object

   ↳ androidx.webkit.WebMessagePortCompat.WebMessageCallbackCompat

The listener for handling MessagePort events. The message callback methods are called on the main thread. If the embedder application wants to receive the messages on a different thread, it can do this by passing a Handler in WebMessagePortCompat.setWebMessageCallback(Handler, WebMessageCallbackCompat). In the latter case, the application should be extra careful for thread safety since WebMessagePort methods should be called on main thread.


Public constructors


Public methods

void onMessage(WebMessagePortCompat port, WebMessageCompat message)

Message callback for receiving onMessage events.

Inherited methods

Public constructors


public WebMessageCallbackCompat ()

Public methods


public void onMessage (WebMessagePortCompat port, 
                WebMessageCompat message)

Message callback for receiving onMessage events.

This method is called only if WebViewFeature.WEB_MESSAGE_CALLBACK_ON_MESSAGE is supported. You can check whether that flag is supported using WebViewFeature.isFeatureSupported(String).

port WebMessagePortCompat: the WebMessagePort that the message is destined for

message WebMessageCompat: the message from the entangled port.