-
Notifications
You must be signed in to change notification settings - Fork 0
Webview Bridge JavascriptObjects
Ender edited this page Mar 7, 2022
·
1 revision
JavascriptObject
s are an easy way to bridge the gap between Java and the webview's Javascript context.
Example Usage:
webview
.getBridge()
.defineObject("test", new JavascriptObject() {
@JavascriptValue
private int twelve = 12;
@JavascriptFunction
public long nanoTime() {
return System.nanoTime();
}
@JavascriptFunction
public void testThrow() {
throw new IllegalStateException("Test throw.");
}
});
Note that await
is required for both functions and properties, since they IPC mechanism is asynchronous. If you wish, you may also pass functions and receive them as JavascriptCallback
in Java. Calling JavascriptCallback#invoke(WebviewBridge, Object... args)
will allow you to call these functions from Java.