Skip to content

Commit

Permalink
Add HybridWebView Android send/receive messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Eilon committed Jun 7, 2024
1 parent 8d53356 commit 1dd1bcf
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void SendMessageButton_Pressed(object sender, EventArgs e)

private void hwv_RawMessageReceived(object sender, HybridWebView.HybridWebViewRawMessageReceivedEventArgs e)
{
statusLabel.Text += e.Message;
Dispatcher.Dispatch(() => statusLabel.Text += e.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
else {
// Android WebView
//hybridWebViewHost.sendMessage(message);
hybridWebViewHost.sendMessage(message);
}

}
Expand All @@ -29,10 +29,18 @@
messageFromCSharp.value += '\r\n' + message;
}

window.chrome.webview.addEventListener('message', arg => {
ReceiveRawMessageFromCSharp(arg.data);
});

if (window.chrome && window.chrome.webview) {
// Windows WebView2
window.chrome.webview.addEventListener('message', arg => {
ReceiveRawMessageFromCSharp(arg.data);
});
}
else {
// Android WebView
window.addEventListener('message', arg => {
ReceiveRawMessageFromCSharp(arg.data);
});
}

</script>
</head>
Expand Down
Loading

0 comments on commit 1dd1bcf

Please sign in to comment.