Difference between revisions of "AppSDK()"

From Engineering Client Portal

Line 64: Line 64:
  
 
=== iAppNotifier ===
 
=== iAppNotifier ===
Client apps subscribe to the App SDK event listener to be notified about App SDK events. To implement, please create a plain old java object (POJO) that implements the interface <code>com.nielsen.app.sdk.IAppNotifier</code>. Do not implement with the main activity class as this creates a strong reference and interferes with memory release.
+
Client apps can subscribe to the App SDK event listener to be notified about App SDK events. To implement this feature, create a plain old java object (POJO) that implements the interface <code>com.nielsen.app.sdk.IAppNotifier</code>. Do not implement with the main activity class as this creates a strong reference and interferes with memory release.
  
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
Line 78: Line 78:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Note that implementing the event listener is '''optional'''.
  
 
==== AppSdk events ====
 
==== AppSdk events ====

Revision as of 17:02, 23 May 2018

Engineering Portal breadcrumbArrow.png Digital breadcrumbArrow.png Android SDK API Reference breadcrumbArrow.png AppSDK()

AppSdk() is the public constructor used for initializing the App SDK Analytics framework.

  • The reference to the App SDK object returned by the Appsdk constructor.
  • App SDK supports multiple instances (max. four) to measure multiple players simultaneously.
  • context, appInfo parameters are mandatory and should not be NULL values.
  • The constructor should never return null.

Debug flag for development environment

Player application developers / integrators can use Debug flag to check whether an App SDK API call made is successful. To activate the Debug flag,

  • Pass the argument + ""nol_devDebug" : "" + "I" + "",", while initializing the App SDK object. The permitted values are
    • 'I' (INFO): Displays the API calls and the input data from the application (validate player name, app ID, etc.). It can be used as certification Aid.
    • 'W' (WARNING): Indicates potential integration / configuration errors or SDK issues.
    • 'E' (ERROR): Indicates important integration errors or non-recoverable SDK issues.
    • 'D' (DEBUG): Debug logs, used by the developers to debug more complex issues.

Once the flag is active, it logs each API call made and the data passed. The log created by this flag is minimal.

Note: DO NOT activate the Debug flag in production evironment.

Syntax

public AppSdk(Context context, JSONObject appInfo, IAppNotifier notifier);

Input Parameters

Parameter Description
context The context from the App
appInfo JSON object that defines the application information.
notifier Client-provided object implementing the iAppNotifier interface. Can be ‘null’ if not provided by client.

Output Parameters

Output Parameters (Return value) Description
A reference to the instance. Else Null object

Notes

JSON object format for appInfo

  JSONObject appSdkConfig = new JSONObject()
          .put("appid", "PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
          .put("appname", "Sample App Name")
          .put("sfcode", "uat-cert")
          .put("custom_key1", "custom_value1")
          .put("custom_key2", "custom_value2");

JSON string format for appInfo

The required items are application name (appName), application ID (appid), designated market area (dma), Nielsen-assigned data node (sfcode), and the country code (ccode).

Note: Notice that all quotes inside the string are escaped with a backslash (\).

"{"appName":"PlayerApp","appid":"PXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX,"sfcode":"us"}"

iAppNotifier

Client apps can subscribe to the App SDK event listener to be notified about App SDK events. To implement this feature, create a plain old java object (POJO) that implements the interface com.nielsen.app.sdk.IAppNotifier. Do not implement with the main activity class as this creates a strong reference and interferes with memory release.

//pass the implementing object to the AppSdk constructor in order to subscribe to the eventlistener:
mAppSdk = new AppSdk(context, appInfo,iappNotifierObject)

Optionally, implement an object derived from the interface, as below. This object will allow listening for events within the App SDK.

public interface iAppNotifier
{
public void onAppSdkEvent(long timestamp, int code, String description);
}

Note that implementing the event listener is optional.

AppSdk events

There are three events currently exposed on the App SDK.

public static final int EVENT_INITIATE = 2000;
  • App SDK notifies that it is going to be initialized.
public static final int EVENT_STARTUP = 2001;
  • The App SDK has just started up. It will happen only after the App SDK has received a valid config file from Nielsen. This is the location in the code to acquire value of userOptOutURLString().
public static final int EVENT_SHUTDOWN = 2002;
  • The App SDK is shutting down. It will happen only when the App SDK is destroyed.