Events Module for Native Android

This section explains the steps to integrate the now.gg Events module with your development environment.

To get started, download the now.gg SDK download package that contains the now.gg Events module and add it to your development environment.

Add SDK Libraries

Start by downloading the now.gg SDK package that contains the Events module libraries and add them to your development environment by following the steps below:

Note: The now.gg SDK package contains the Events module and sample code.

1. Extract the compressed now.gg Events module and locate the .aar file in the package:

 Events.aar

2. Add the following dependency to the build.gradle file of your game:

dependencies {
         implementation fileTree(dir: 'libs', include: ['*.aar'])
 }


Use now.gg Events Module

Once the module has been successfully imported, you can now use the now.gg Events Module.

We have included some of the sample commands/events as a reference for your implementation.

You can use the NowGGEventsSdkManager class to trigger events as illustrated below:

1. Open Url

You can call the openUrl function of the NowGGEventsSdkManager class to open the provided URL in a new browser window, as illustrated below:

string url = "https://example.com";

 NowGGEventsSdkManager.getInstance().openUrl(url, activityContext);
Note: Please ensure the openUrl method is called from the launchable activity of your app.

Reference : Additional information associated with openURL() can be found here.


2. Send Events and Data to the HTML Page

You can call the sendEventToBrowser function of the NowGGEventsSdkManager class, along with the required parameters, to send the events and data to your HTML page and handle it there.

a. Send Events to HTML Page

string eventName = "test-event";
 string eventData = "test-data";

 NowGGEventsSdkManager.getInstance().sendEventToBrowser(eventName, eventData, activityContext);

Reference : Additional information associated with sendEventToBrowser() can be found here.

b. Handle Events on HTML Page

After the data has been sent to your HTML, you can handle it there, as illustrated below:

const eventCallbackFunction = (event) => {
 console.log(event.eventName); // event1
 console.log(event.eventData); // eventData1
  
 // Perform event-based handling here
 }; 

3. Send Events and Data to the Android App

You can call the sendEventToApp function of the now.gg Embed Module with the required arguments to send events and data to your Android app and handle them.

a. Sending Events to the Android App

The sendEventToApp sends a custom event and associated data to your app using the NowIfp interface of now.gg Embed module, as illustrated below:

const sendEventToApp = () => {
     const eventName = 'CustomEvent';
     const eventData = JSON.stringify({
         Sample: 'case'
     });
     NowIfp.sendEventToApp(eventName, eventData);
 };

b. Handling Events in Your Android App

After the data has been sent to your Android app, you can handle it by implementing the following steps:

1. Declare an Event Callback and Register a Listener

Define a callback function to handle incoming events.

NowGGEventCallback eventCallback = (String eventName, String eventData) -> {
     // Perform tasks based on the eventName and eventData
     };

 NowGGEventsSdkManager.getInstance().registerEventListener(this, eventCallback);
2. Disposing of the Event Listener

When discarding the parent activity, it is essential to dispose of the event listener to avoid memory leaks and unnecessary callbacks. This should typically be done during cleanup, such as in your app’s onDestroy() method.

NowGGEventsSdkManager.getInstance().unregisterEventListener(this);

4. Retrieve app Launch Data in your App

We have provided two methods to retrieve the app launch data you sent to your Android App from the HTML page.

a. Use the bundle to retrieve all app launch data parameters

You can call the getAppLaunchDataBundle function of the NowGGEventsSdkManager class, as illustrated below:

 //Retrieves a bundle of all app launch data params
 
 Bundle bundle = NowGGEventsSdkManager.getInstance().getAppLaunchDataBundle(activityContext);

Reference: Additional information associated with getAppLaunchDataBundle() can be found here.

b. Use property name to retrieve a specific app launch data parameter

You can call the getAppLaunchDataProperty() function of the NowGGEventsSdkManager class, along with the property name, to retrieve a specific app launch data parameter, as illustrated below:

 //Retrieves an app launch data property by name 

 String property = NowGGEventsSdkManager.getInstance().getAppLaunchDataProperty("event_name", activityContext);
Note: Returns an empty string if the property is not found.

Reference: Additional information associated with getAppLaunchDataProperty() can be found here.

×

Events Module

Events Module for Native Android

Events Module

Document Rev. 1.0

Text copied to clipboard
Link copied to clipbord
Questions? Please reach out to us at dev-support@now.gg