Android Background Foreground: Difference between revisions
From Engineering Client Portal
No edit summary |
No edit summary |
||
Line 33: | Line 33: | ||
You must now open SdkBgFgDetectionUtility class and set the package name header | You must now open SdkBgFgDetectionUtility class and set the package name header | ||
to the package name for your specific application: | to the package name for your specific application: | ||
<syntaxhighlight = "java"> | <syntaxhighlight lang= "java"> | ||
//Change package to your project package | //Change package to your project package | ||
package com.nielsen.myapplication; | package com.nielsen.myapplication; | ||
Line 41: | Line 41: | ||
Instantiate the SdkBgFgDetectionUtility within the onCreate() method of your app’s | Instantiate the SdkBgFgDetectionUtility within the onCreate() method of your app’s | ||
inherited Application Class. | inherited Application Class. | ||
<syntaxhighlight = "java"> | <syntaxhighlight lang= "java"> | ||
SdkBgFgDetectionUtility sdkUtility = new SdkBgFgDetectionUtility(this); | SdkBgFgDetectionUtility sdkUtility = new SdkBgFgDetectionUtility(this); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 48: | Line 48: | ||
Call the method handleSdkLifecyleEvents to let the class start handling | Call the method handleSdkLifecyleEvents to let the class start handling | ||
foreground/background state measurement. | foreground/background state measurement. | ||
<syntaxhighlight = " | <syntaxhighlight lang= "java"> | ||
sdkUtility.handleSdkLifecycleEvents(); | sdkUtility.handleSdkLifecycleEvents(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 54: | Line 54: | ||
== Sample Application Class Implementation == | == Sample Application Class Implementation == | ||
Below is an example application class implementation. | Below is an example application class implementation. | ||
<syntaxhighlight = " | <syntaxhighlight lang= "java"> | ||
package com.nielsen.myapplication; | package com.nielsen.myapplication; | ||
import android.app.Application; | import android.app.Application; |
Revision as of 00:34, 8 November 2017
Measuring the Android Foreground/Background State
This guide shows you how to integrate the SdkBgFgDetectionUtility class which Nielsen has made available for measurement of Android Foreground/Background state. Correct measurement of foreground/background state is crucial to Static App measurement within Nielsen Digital Content Ratings (DCR).
Foreground and Background State Measurement
Foreground/Background state measurement may be implemented in multiple ways for Android. This includes
- Enable the Nielsen SDK to measure background/foreground state by making
the relevant update to the AndroidManifest.
- Implement the required methods.
- Integrate Nielsen’s SdkBgFgDetectionUtility class within your Custom
Application Class. This document is intended to demonstrate how to integrate the SdkBgFgDetectionUtility class. The SdkBgFgDetectionUtility is compatible with Android 4+. If your Android application does not have an existing Custom Application Class, then foreground/background measurement should be achieved through the use of the AndroidManifest solution.
Integrating the Utility Class
There are four main steps to integrating the SdkBgFgDetectionUtility class for use in handling foreground/background state notification.
Add the Class
First copy and paste the SdkBgFgDetectionUtility.java class into your project.
Link the Class to your Project
You must now open SdkBgFgDetectionUtility class and set the package name header to the package name for your specific application:
//Change package to your project package
package com.nielsen.myapplication;
Instantiate the Utility
Instantiate the SdkBgFgDetectionUtility within the onCreate() method of your app’s inherited Application Class.
SdkBgFgDetectionUtility sdkUtility = new SdkBgFgDetectionUtility(this);
Initialise the Class
Call the method handleSdkLifecyleEvents to let the class start handling foreground/background state measurement.
sdkUtility.handleSdkLifecycleEvents();
Sample Application Class Implementation
Below is an example application class implementation.
package com.nielsen.myapplication;
import android.app.Application;
public class myApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
SdkBgFgDetectionUtility sdkUtility = new SdkBgFgDetectionUtility(this);
sdkUtility.handleSdkLifecycleEvents();
}
}