Implement game-events listener
This document helps you implement event listeners within your native apps.
Last updated
Was this helpful?
This document helps you implement event listeners within your native apps.
Last updated
Was this helpful?
You may want to listen to the events Gamezop games broadcast if you have custom UI overlays to implement at the occurrence of specific events, or if you want to take any action when a particular in-game event occurs. This document guides you on how you can do that.
Guides are available for:
If you have our game running within a WebView, you can listen to events with the following steps:
Let's say your WebView is defined as myWebView
. Here's a code-block for enabling Javascript:
class
to receive eventsWe will create a class called gamezopWebAppInterface
. Within that, we will define a getGameEvents
function. Do not change the name of the function, as this is the function our games will call to pass events to the app.
When our game calls the function, it will pass a stringified JSON object as an argument to the function which will have all the data on the event being sent.
Upon receiving the events, for simplicity sake, let's say we want to just print them in Toasts. You can, of course, replace this with your desired actions.
Where you initialise the Webview, you need to add a Javascript interface there. This is basically the class you created in Step 2.
That's all. You're good to go!
For Flutter apps, you just need to add a JavaScript channel with the name AndroidBridge
.
For iOS applications, you just need to add a JS Message Handler.