Mobile SDK Android

From ePrize Developers Wiki

(Difference between revisions)
Jump to: navigation, search
m (webViewDidFireEvent - Adding disclaimer)
Current revision (16:47, 24 August 2018) (edit) (undo)
(Class Documentation)
 
(13 intermediate revisions not shown.)
Line 1: Line 1:
== OS Support ==
== OS Support ==
-
The ePrize Mobile SDK is built for Android apps targeting <b>API level 9 and higher. </b>
+
The [[Mobile_SDK|HelloWorld Mobile SDK]] is built for Android apps targeting <b>API level 14 and higher. </b>
 +
== Version & Release Notes ==
-
== Getting Started ==
+
<b>SDK Version:</b> 2.0.6
-
The ePrize Mobile SDK is designed to be an easy and practical way to retrieve a list of active promotions your organization is running with ePrize, Inc. Once you retrieve a list of active promotions, you can use the SDK to launch a given promotion using an instance of the SDK's built-in web view controller, where the specified promotion will be loaded into a customizable web view and presented to the user - all while remaining in your mobile application.
+
<b>Release Notes:</b>
-
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Please note:</b> Using this SDK requires a valid client key provided by ePrize. If you do not have a client key, please contact your account team or Producer.</i></div>
+
* Updates to dependent librarys
 +
* Switch to Retrofit + RxJava
-
=== Key Concepts ===
+
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Note on naming:</b> You will notice that the SDK uses the historical company name “ePrize” in the framework name, and “EPZ” for the class namespace. Future releases of the SDK may include updates to these names and namespaces to reflect the new company name, HelloWorld, which was introduced in 2014. </i></div>
-
<b>Shared Library</b><br />
+
== Key Concepts ==
-
This SDK has a class named [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]], which is a Singleton class that is the workhorse of the SDK. Since it is a Singleton, you will not create instances of it, but rather, will simply reference it via the class's [[#getInstance|getInstance()]] method.
+
-
<b>Configuration Keys</b><br />
+
=== Singleton Classes ===
-
This SDK uses a concept of configuration keys to access data and instantiate views. Each active promotion that your organization has with ePrize will have an associated configuration key. When the list of active promotions is retrieved, you will have access to an array of these configuration keys. You will use the keys to get access to specific promotion configurations ([[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]]), which you can use to launch a promotion right inside of your app. The array of keys is stored in the library's instance for access anywhere in your application.
+
The SDK includes a number of Singleton classes which you will not create instances of, but rather, can simply reference via the class' getInstance() method. The Singleton classes used in the SDK include:
 +
* [[Mobile_SDK_Android:_EPZAnalyticsService|EPZAnalyticsService]]
 +
* [[Mobile_SDK_Android:_EPZBusProvider|EPZBusProvider]]
 +
* [[Mobile_SDK_Android:_EPZPromoLibrary|EPZPromoLibrary]]
-
=== Step 1: Obtain the EPrizeMobileSDK ===
+
Additionally, the SDK includes a class named [[Mobile_SDK_Android:_EPZConstants|EPZConstants]], which is a simple storage class for constants defined for use in the SDK, and as a convenience for applications using the SDK, so they can make use of the constants as needed (e.g. to avoid typos in string values, to use when defining map keys for configuration options, etc).
-
Please contact your account team or Producer to obtain your copy of the ePrize Mobile SDK.
+
=== Event Dispatching ===
 +
Version 2.0 of this SDK includes a major shift in the callback logic used for events. Where version 1.0 used listeners as the primary method of implementing callbacks from the SDK, version 2.0 introduces the use of the Event Bus by [http://square.github.io/otto/ Otto], which the SDK uses to post events. Your app simply needs to register with the [[Mobile_SDK_Android:_EPZBusProvider|EPZBusProvider]] and subscribe to whichever events are applicable for your needs.
-
=== Step 2: Add EPrizeMobileSDK Library to your Project's References ===
+
=== Configuration Keys ===
 +
The SDK uses a concept of configuration keys to access data about promotions and instantiate certain views. Each active promotion will have an associated configuration key. When the list of active promotions is retrieved, you will have access to an array of these configuration keys. You will use the keys to get access to specific promotion configurations ([[Mobile_SDK_Android:_EPZPromoConfiguration|EPZPromoConfiguration]]). The array of keys is stored in the [[Mobile_SDK_Android:_EPZPromoLibrary|EPZPromoLibrary]] instance for access anywhere in your application.
-
In order to utilize the EPrizeMobileSDK, you'll need to link to it in your project properties.
+
== Getting Started ==
-
<ol>
+
-
<li>Import the EPrizeMobileSDK project into Eclipse.</li>
+
-
<li>Right-click on your Android application project and select "Properties"</li>
+
-
<li>Select "Android" in the left side navigation</li>
+
-
<li>Under the "Library" section of the dialog window, click "Add..." and select EPrizeMobileSDK.</li>
+
-
</ol>
+
-
=== Step 3: Import SDK classes as necessary ===
+
The SDK is designed to be an easy and practical way to retrieve a list of active promotions your organization is running with HelloWorld, Inc. Once you retrieve a list of active promotions, you can use the SDK to launch a given promotion using an instance of the SDK's built-in web view controller, where the specified promotion will be loaded into a customizable web view and presented to the user - all while remaining in your mobile application.
-
In any class file that needs to utilize the SDK, you will need to import the necessary files. You can consult the [[#Class_Documentation:_EPZPromoLibrary|EPrizeMobileSDK Class Documentation]] section below for more information about each of the classes included in the SDK.
+
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Please note:</b> Using this SDK requires a valid client key provided by HelloWorld. If you do not have a client key, please contact your account team or Producer. </i></div>
-
== Sample Integration ==
+
=== Obtain the EPrizeMobileSDK ===
-
The following section outlines steps to get up and running with the EPrizeMobileSDK in your app. These steps provide small code snippets that you can use as reference in your own project. If you need more information about any of the classes, properties, and/or methods used in any of these snippets, please consult the applicable class documentation provided.
+
Please contact your account team or Producer to obtain your copy of the SDK.
-
=== Update your app's Manifest file ===
+
=== Add EPrizeMobileSDK to your project's references ===
-
 
+
-
To be able to utilize this SDK, you will need to make a few updates to your app's manifest file.
+
-
 
+
-
Set up permissions (if not already included):
+
 +
==== Gradle Project Setup ====
 +
<ol>
 +
<li>Copy the "HelloWorld_MobileSDK-X.X.aar" into your projects "libs" folder, where "X.X" represents the latest version of the library.</li>
 +
<li>Make sure your build.gradle file for your project's main module includes the following in addition to the standard Android application Gradle file setup: </li>
<pre>
<pre>
-
<uses-permission android:name="android.permission.INTERNET" />
+
repositories {
-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
mavenCentral()
-
</pre>
+
-
Include EPZPromoWebViewController activity in the list of activities:
+
// add this for use with MobileSDK
 +
flatDir {
 +
dirs 'libs'
 +
}
 +
}
-
<pre>
+
def mSdkVersion = '2.0'
-
<activity android:name="com.eprize.mobile.eprizemobilesdk.EPZPromoWebViewController"
+
-
android:configChanges="orientation|keyboardHidden|screenSize"></activity>
+
-
</pre>
+
-
<i><b>Important Note:</b> It is highly recommended that you set the android:configChanges attribute as specified above. This will ensure that the activity is not completely destroyed and re-created when the device's orientation changes, or when the keyboard is hidden. If this is not done, and the activity is destroyed and re-created, the user will lose their place in the promotion they are visiting, and be returned to the promo's home page, resulting in an unpleasant user experience. Additionally, if you wish to lock the activity's orientation to match your app, you can set the android:screenOrientation attribute accordingly.</i>
+
android {
 +
compileSdkVersion 24
 +
buildToolsVersion '27.0.3'
 +
compileOptions {
 +
sourceCompatibility JavaVersion.VERSION_1_8
 +
targetCompatibility JavaVersion.VERSION_1_8
 +
}
 +
}
-
=== Configure the EPZPromoLibrary, Set its Listener, & Fetch Promotion Configurations ===
+
dependencies {
-
 
+
impllementation "com.eprize.mobile.eprizemobilesdk:HelloWorld_MobileSDK:$mSdkVersion@aar"
-
To use the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]], you need to configure it to your needs. You will create a Map (String, Object) that you will pass in to the library's [[#configure|configure()]] method. There are 2 required key/value pairs that must be specified in this Map: clientKey (String), and appContext (Context). There are a handful of other key/value pairs you can configure, which are outlined further in the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] documentation. Note that an exception will be thrown if either the clientKey or appContext key/value pairs are invalid.
+
-
 
+
implementation 'com.squareup:otto:1.3.8' // MobileSDK dependency
-
You will also need to set the listener so you can implement the callback methods that are called on promotion retrieval success and failure.
+
implementation 'com.google.code.gson:gson:2.8.5' // MobileSDK dependency
-
 
+
implementation 'com.squareup.retrofit2:retrofit:2.4.0' // MobileSDK dependency
-
Once you have configured the library, you are safe to fetch the promotion configurations via the [[#fetchPromotionConfigurations|fetchPromotionConfigurations()]] method.
+
implementation 'com.squareup.retrofit2:converter-gson:2.4.0' // MobileSDK dependency
-
 
+
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0' // MobileSDK dependency
-
<i><b>Important Note:</b> It is highly recommended that you configure the SDK as early as possible in your app's main activity, so it will be configured and ready when you need it.</i>
+
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' // MobileSDK dependency
-
 
+
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' // MobileSDK dependency
-
 
+
implementation "io.reactivex.rxjava2:rxjava:2.1.16" // MobileSDK dependency
-
=== Implement Applicable Callback Methods ===
+
-
 
+
-
In order to receive access to the library's callback methods, you need to implement [[#EPZListener_Implementation_Methods|EPZListener]] and its applicable methods. Wherever you choose to integrate the retrieval of configuration data, you will need to implement the [[#promotionConfigurationsRetrieved|promotionConfigurationsRetrieved()]] and [[#promotionConfigurationsFailedWithError|promotionConfigurationsFailedWithError()]] methods. Per the naming of each method, these methods are called when the promotion configurations are successfully or unsuccessfully retrieved, respectively.
+
-
 
+
-
 
+
-
=== Hint: Use a final variable to reference EPZPromoLibrary ===
+
-
 
+
-
If you're referencing the shared library more than once, it makes sense to create a final variable you can use to shorten your code a bit. Then, any time you need to reference the library, you can just reference it via the variable:
+
-
 
+
-
<pre>
+
-
private final EPZPromoLibrary library = EPZPromoLibrary.getInstance();
+
-
</pre>
+
-
 
+
-
 
+
-
=== Full Code Sample ===
+
-
 
+
-
Below is a full code sample of importing, configuring, and implementing the EPrizeMobileSDK, based on the steps outlined above. Note that this sample is a bare-bones app, and only applicable code is shown for the sake of brevity and clarity.
+
-
 
+
-
<pre>
+
-
package com.eprize.mobile.testproject;
+
-
 
+
-
import java.util.HashMap;
+
-
import java.util.Map;
+
-
 
+
-
import android.app.Activity;
+
-
import android.os.Bundle;
+
-
import android.view.Menu;
+
-
 
+
-
import com.eprize.mobile.eprizemobilesdk.EPZPromoLibrary;
+
-
import com.eprize.mobile.eprizemobilesdk.EPZPromoLibrary.EPZListener;
+
-
 
+
-
public class MainActivity extends Activity implements EPZListener {
+
-
 
+
-
private final EPZPromoLibrary library = EPZPromoLibrary.getInstance();
+
-
 
+
-
@Override
+
-
protected void onCreate(Bundle savedInstanceState) {
+
-
super.onCreate(savedInstanceState);
+
-
setContentView(R.layout.activity_main);
+
-
+
-
// Create configuration map
+
-
Map<String, Object> configOptions = new HashMap<String, Object>();
+
-
configOptions.put("clientKey", "your_client_key");
+
-
configOptions.put("appContext", this);
+
-
+
-
// Call configure method
+
-
try {
+
-
library.configure(configOptions);
+
-
} catch (Exception configException) {
+
-
// Handle exception
+
-
}
+
-
+
-
// Set library listener
+
-
library.setListener(this);
+
-
 
+
-
// Fetch promotion configurations
+
-
try {
+
-
library.fetchPromotionConfigurations();
+
-
} catch (Exception fetchException) {
+
-
// Handle exception
+
-
}
+
-
}
+
-
 
+
-
@Override
+
-
public void promotionConfigurationsRetrieved(String[] promoKeys) {
+
-
// promoKeys is an array of promotion configuration keys.
+
-
// Use this array as needed to display a promotion, list
+
-
// of promotions, or other call-to-action as needed.
+
-
}
+
-
 
+
-
@Override
+
-
public void promotionConfigurationsFailedWithError(Exception error) {
+
-
// Handle exception
+
-
}
+
-
 
+
}
}
</pre>
</pre>
 +
where "$mSdkVersion" corresponds to the version of the library used.
 +
</ol>
 +
=== Import SDK classes as necessary ===
-
=== Launching a Promotion ===
+
In any class file that needs to utilize the SDK, you will need to import the necessary files. You can consult the [[#Class_Documentation|Class Documentation]] section below for more information about each of the classes included in the SDK.
-
If you have at least one active promotion configuration to which you give an accompanying call-to-action, you’ll need a way to display the promotion in your app. To do this, you can simply call the library's [[#launchPromotionForKey|launchPromotionForKey()]] method. This method will create a new activity with a web view and toolbar, and present it automatically, loaded with the given promotion.
+
==== Submit Required Information to HelloWorld ====
-
<pre>
+
Once you have your project set up in the Google Developers Console as specified above, you will need to <b>submit the following app information to your HelloWorld account team or Producer</b>:
-
String key = library.getPromoKeys()[0];
+
-
library.launchPromotionForKey(key);
+
-
</pre>
+
-
Alternatively, you can call the library's [[#launchWebViewWithURL|launchWebViewWithURL()]] method, passing in a URL to load into the web view instance. This method, like the one above, will create a new activity with a web view and toolbar, and present it automatically, loaded with the given URL.
+
* App Package <i>(e.g. com.helloworld.mobilesdk.android.demo) <b>- See note below</b></i>
 +
* App Name <i>(e.g. MobileSDK Demo App)</i>
-
<pre>
+
== Sample Integration ==
-
String customURL = "http://www.eprize.com/";
+
-
library.launchWebViewWithURL(customURL);
+
-
</pre>
+
-
== Class Documentation: EPZPromoLibrary ==
+
The following section outlines steps to get up and running with the EPrizeMobileSDK in your app. These steps provide small code snippets that you can use as reference in your own project. If you need more information about any of the classes, properties, and/or methods used in any of these snippets, please consult the applicable class documentation provided.
-
=== Overview ===
+
=== Update your app's Manifest file ===
-
The EPZPromoLibrary class is a Singleton class that provides the necessary logic to connect to the ePrize servers. It is the workhorse of the SDK, providing the methods to retrieve and store the full list of promotion configurations.
+
To be able to utilize this SDK, you will need to make a few updates to your app's manifest file.
-
Since this class is a Singleton, you will not create an instance of it. Rather, you will simply reference it via the [[#getInstance|getInstance()]] method in order to access the data stored within the class, and methods to be called from the class.
+
Set up permissions (if not already included):
-
 
+
-
For instance, to access the array of promotion configuration keys:
+
<pre>
<pre>
-
EPZPromoLibrary.getInstance().getPromoKeys();
+
<uses-permission android:name="android.permission.INTERNET" />
 +
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</pre>
</pre>
-
...or to fetch promotion configurations:
+
Include the SDK's built-in activities in the list of activities:
<pre>
<pre>
-
EPZPromoLibrary.getInstance().fetchPromotionConfigurations();
+
<activity android:name="com.eprize.mobile.eprizemobilesdk.EPZPromoWebViewController"
 +
android:configChanges="orientation|keyboardHidden|screenSize" />
</pre>
</pre>
 +
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Important Note:</b> It is highly recommended that you set the android:configChanges attribute as specified above. This will ensure that the activity is not completely destroyed and re-created when the device's orientation changes, or when the keyboard is hidden. If this is not done, and the activity is destroyed and re-created, the user will lose their place in the promotion they are visiting, and be returned to the promo's home page, resulting in an unpleasant user experience. Additionally, if you wish to lock the activity's orientation to match your app, you can set the android:screenOrientation attribute accordingly.</i></div>
-
=== Constants ===
+
=== Configure the EPZPromoLibrary and Register with Event Bus ===
-
<ul>
+
-
<li>VERSION (float): The version of the SDK.</li>
+
-
<li>NO_CLIENT_KEY_SET (String): Message attached to configuration exception when no client key is set.</li>
+
-
<li>NO_APP_CONTEXT_SET (String): Message attached to configuration exception when no app context is set.</li>
+
-
</ul>
+
 +
To use the [[Mobile_SDK_Android:_EPZPromoLibrary|EPZPromoLibrary]] , you need to configure them to your needs. You will create a Map (String, Object) that you will pass in to the class' configure() method. You will also need to set up the register and unregister methods with the [[Mobile_SDK_Android:_EPZBusProvider|EPZBusProvider]] instance in preparation for subscribing to events.
-
=== Public Methods ===
+
The code sample below includes only the required key/value pairs for the configuration options Map, which utilize constant values found in the [[Mobile_SDK_Android:_EPZConstants|EPZConstants]] class. There are a handful of other key/value pairs you can configure, which are outlined further in the [[#Class_Documentation|Class Documentation]] for each class, respectively.
-
==== getInstance ====
+
-
<pre>
+
-
public static synchronized getInstance()
+
-
</pre>
+
-
<b>Returns</b><br />
 
-
The singleton library instance.
 
- 
- 
-
==== configure ====
 
<pre>
<pre>
-
public void configure(Map<String, Object> options)
+
private static final String CLIENT_KEY_PUBLIC = "dev_multi";
-
</pre>
+
private final EPZPromoLibrary mLibrary = EPZPromoLibrary.getInstance();
-
Configures the library with options set in the "options" argument. This method <b>must</b> be called before retrieving promotions via the [[#fetchPromotionConfigurations|fetchPromotionConfigurations()]] method.
+
private final Bus mBus = EPZBusProvider.getInstance();
 +
@Override
 +
protected void onCreate(Bundle savedInstanceState) {
 +
super.onCreate(savedInstanceState);
 +
...
 +
// Register with EPZBusProvider so we can subscribe to EPZ events.
 +
mBus.register(this);
 +
 +
// Set configuration options.
 +
Map<String, Object> configOptions = new HashMap<String, Object>();
 +
configOptions.put(EPZConstants.CONFIG_KEY_CLIENT_KEY, CLIENT_KEY_PUBLIC);
 +
configOptions.put(EPZConstants.CONFIG_KEY_APP_CONTEXT, this);
 +
 +
// Configure library .
 +
try {
 +
mLibrary.configure(configOptions);
 +
} catch (Exception configException) {
 +
// Handle exception as needed.
 +
}
 +
}
-
<b>Parameters</b><br />
+
@Override
-
<i>options</i> A map of options used for configuration. Valid options (and their value type) are listed below:
+
protected void onDestroy() {
-
<ul>
+
super.onDestroy();
-
<li><b>clientKey</b> (String) &nbsp;<i>required</i><br />Your client key</li>
+
mBus.unregister(this);
-
<li><b>appContext</b> (Context) &nbsp;<i>required</i><br />A Context of the application package implementing EPZListener.</li>
+
}
-
<li><b>toolbarBackground</b> (int)<br />A resource id for the web view toolbar background, which should be able to repeat horizontally to stretch and fill the width of the window. The toolbar is shown at the bottom of the web view activity.<br /><span style="padding-left: 30px;"><i>Default: Dark charcoal gray gradient with soft gloss effect.</i></span></li>
+
-
<li><b>closeButton</b> (Button)<br />The close button for the web view toolbar, used to close the activity.<br /><span style="padding-left: 30px;"><i>Default: White X icon</i></span></li>
+
-
<li><b>backButton</b> (Button)<br />The back button for the web view toolbar, used to navigate back in the web view history (when applicable).<br /><span style="padding-left: 30px;"><i>Default: White left-facing arrow.</i></span></li>
+
-
<li><b>forwardButton</b> (Button)<br />The forward button for the web view toolbar, used to navigate forward in the web view history (when applicable).<br /><span style="padding-left: 30px;"><i>Default: White right-facing arrow.</i></span></li>
+
-
<li><b>refreshButton</b> (Button)<br />The refresh button for the web view toolbar, used to refresh the web view. This button's visibility is swapped with the loading icon when a web view is loading content.<br /><span style="padding-left: 30px;"><i>Default: White refresh icon.</i></span></li>
+
-
<li><b>loadingIcon</b> (ViewGroup)<br />The loading icon for the web view toolbar, used when the web view is loading content. This icon's visibility is swapped with the refresh button after the web view is done loading.<br /><span style="padding-left: 30px;"><i>Default: White spin wing animation.</i></span></li>
+
-
<li><b>toolbarDivider</b> (int)<br />A resource id for the web view toolbar dividers.<br /><span style="padding-left: 30px;"><i>Default: Dark hairline with soft white right border.</i></span></li>
+
-
<li><b>dividerVisibility</b> (int)<br />A View constant to specify the visibility of the web view toolbar dividers (e.g. View.VISIBLE)<br /><span style="padding-left: 30px;"><i>Default: View.INVISIBLE</i></span></li>
+
-
</ul>
+
-
 
+
-
 
+
-
==== promotionConfigurationForKey ====
+
-
<pre>
+
-
public EPZPromoConfiguration promotionConfigurationForKey(String key)
+
-
</pre>
+
-
Returns an [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] object for the specified configuration key passed in, or null if an invalid configuration key is used.
+
-
 
+
-
 
+
-
==== fetchPromotionConfigurations ====
+
-
<pre>
+
-
public void fetchPromotionConfigurations() throws Exception
+
</pre>
</pre>
-
Retrieves a list of promotion configurations from the ePrize servers. This method makes an asynchronous request to retrieve a list of promotion configuration keys, using the clientKey value set when configuring the library.
 
-
<b>Throws</b><br />An exception, if no client key or app context have been set in the library's [[#configure|configure()]] method.
+
=== Fetch Promotion Configurations and Subscribe to Events ===
 +
Once you have configured the [[Mobile_SDK_Android:_EPZPromoLibrary|EPZPromoLibrary]], you are safe to fetch the promotion configurations via the [[Mobile_SDK_Android:_EPZPromoLibrary#fetchPromotionConfigurations|fetchPromotionConfigurations()]] method.
-
==== launchPromotionForKey ====
 
<pre>
<pre>
-
public void launchPromotionForKey(String key)
+
mLibrary.fetchPromotionConfigurations();
</pre>
</pre>
-
Creates and displays a new EPZPromoWebViewController activity, with the promotion for the specified configuration key loaded into the web view. If the promotion's configuration object has the [[#getOpenInNativeBrowser|getOpenInNativeBrowser()]] value set to true, the device's native browser will be launched rather than using the built-in EPZPromoWebViewController.
 
-
<b>Parameters</b><br />
+
You will also need to set up a @Subscribe method to handle the [[Mobile_SDK_Android:_EPZPromotionConfigurationFetchEvent|EPZPromotionConfigurationFetchEvent]] dispatched on completion of fetching the configurations.
-
<i>key</i> A promotion configuration key.
+
- 
-
==== launchWebViewWithURL ====
 
<pre>
<pre>
-
public void launchWebViewWithURL(String url)
+
@Subscribe
 +
public void handlePromotionConfigurationFetchEvent(EPZPromotionConfigurationFetchEvent event) {
 +
if (event.error == null) {
 +
// Successfully retrieved promotion configurations.
 +
} else {
 +
// There was an error fetching configurations - handle as needed.
 +
}
 +
}
</pre>
</pre>
-
Creates and displays a new EPZPromoWebViewController activity, with the specified URL loaded into the web view.
 
-
<b>Parameters</b><br />
 
-
<i>url</i> The URL to load into the web view.
 
 +
=== Launching a Promotion ===
-
==== setListener ====
+
If you have at least one active promotion configuration to which you give an accompanying call-to-action, you’ll need a way to display the promotion site in your app. To do so, get a reference to one of the [[Mobile_SDK_Android:_EPZPromoConfiguration|EPZPromoConfiguration]] objects and call one of the launch methods in the [[Mobile_SDK_Android:_EPZPromoLibrary|EPZPromoLibrary]].
-
<pre>
+
-
public void setListener(EPZListener targetListener)
+
-
</pre>
+
-
Sets the listener for the library. The listener that is set must implement the [[#EPZListener_Implementation_Methods|implementation methods]].
+
-
 
+
-
<b>Parameters</b><br />
+
-
<i>targetListener</i> The listener that implements EPZListener.
+
 +
<blockquote style="background:#ffd; border:1px solid #ddc; padding:20px;">If you do not wish to use the SDK's built-in [[Mobile_SDK_Android:_EPZPromoWebViewController|EPZPromoWebViewController]], you can use the SDK's [[Mobile_SDK_Android:_EPZWebViewFragment|EPZWebViewFragment]] in your own Activity. For more information on using your own Activity, visit the [[Mobile_SDK_Android:_EPZWebViewFragment|EPZWebViewFragment]] page.</blockquote>
-
==== getClientKey ====
 
<pre>
<pre>
-
public String getClientKey()
+
if (mLibrary.getPromoKeys() != null && mLibrary.getPromoKeys().length > 0) {
 +
EPZPromoConfiguration firstConfig = mLibrary.promotionConfigurationForKey(mLibrary.getPromoKeys()[0]);
 +
mLibrary.launchPromotionForKey(firstConfig.getConfigKey());
 +
}
</pre>
</pre>
-
Returns the client key value. This is a convenience method to read and return the value of the client key that was set in the [[#configure|configure()]] method. Note that there is no way to set the client key outside of the [[#configure|configure()]] method.
 
 +
If you would like to handle any web view or lifecycle events, you can set up a @Subscribe method for the [[Mobile_SDK_Android:_EPZPromoWebViewEvent|EPZPromoWebViewEvent]] and/or the [[Mobile_SDK_Android:_EPZPromoWebViewLifecycleEvent|EPZPromoWebViewLifecycleEvent]].
-
==== getAppContext ====
 
<pre>
<pre>
-
public Context getAppContext()
+
@Subscribe
 +
public void handlePromoWebViewEvent(EPZPromoWebViewEvent event) {
 +
// Handle the event fired from the web view here as needed. Event name found via event.eventName
 +
}
 +
@Subscribe
 +
public void handlePromoWebViewLifecycleEvent(EPZPromoWebViewLifecycleEvent event) {
 +
// Handle lifecycle events as needed. Event name found via event.eventName
 +
if (event.error != null) {
 +
// Handle error as needed.
 +
}
 +
}
</pre>
</pre>
-
Returns the app context. This is a convenience method to read and return the value of the app context that was set in the [[#configure|configure()]] method. Note that there is no way to set the app context outside of the [[#configure|configure()]] method.
 
 +
== Class Documentation ==
 +
The SDK includes a number of available classes, whose specific documentation pages can be accessed by clicking one of the links below.
-
==== getPromotionConfigurations ====
+
<b>com.eprize.mobile.eprizemobilesdk</b>
-
<pre>
+
:* [[Mobile_SDK_Android:_EPZAnalyticsService|EPZAnalyticsService]]
-
public Map<Integer, EPZPromoConfiguration> getPromoConfigurations()
+
:* [[Mobile_SDK_Android:_EPZBroadcastReceiver|EPZBroadcastReceiver]]
-
</pre>
+
:* [[Mobile_SDK_Android:_EPZBusProvider|EPZBusProvider]]
-
Returns a map of promotion configurations, as instances of [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] objects.
+
:* [[Mobile_SDK_Android:_EPZConstants|EPZConstants]]
 +
:* [[Mobile_SDK_Android:_EPZIntentService|EPZIntentService]]
 +
:* [[Mobile_SDK_Android:_EPZPreferenceItem|EPZPreferenceItem]]
 +
:* [[Mobile_SDK_Android:_EPZPromoConfiguration|EPZPromoConfiguration]]
 +
:* [[Mobile_SDK_Android:_EPZPromoLibrary|EPZPromoLibrary]]
 +
:* [[Mobile_SDK_Android:_EPZPromoWebViewController|EPZPromoWebViewController]]
 +
:* [[Mobile_SDK_Android:_EPZString|EPZString]]
 +
:* [[Mobile_SDK_Android:_EPZWebViewFragment|EPZWebViewFragment]]
-
 
+
<b>com.eprize.mobile.eprizemobilesdk.events</b>
-
==== getPromoKeys ====
+
:* [[Mobile_SDK_Android:_EPZAnalyticsEventTrackedEvent|EPZAnalyticsEventTrackedEvent]]
-
<pre>
+
:* [[Mobile_SDK_Android:_EPZClosePromoWebViewEvent|EPZClosePromoWebViewEvent]]
-
public String[] getPromoKeys()
+
:* [[Mobile_SDK_Android:_EPZPromotionConfigurationFetchEvent|EPZPromotionConfigurationFetchEvent]]
-
</pre>
+
:* [[Mobile_SDK_Android:_EPZPromoWebViewEvent|EPZPromoWebViewEvent]]
-
Returns an array of promotion configuration keys.
+
:* [[Mobile_SDK_Android:_EPZPromoWebViewLifecycleEvent|EPZPromoWebViewLifecycleEvent]]
-
 
+
:* [[Mobile_SDK_Android:_EPZWebViewCloseWindowEvent|EPZWebViewCloseWindowEvent]]
-
 
+
:* [[Mobile_SDK_Android:_EPZWebViewCreateWindowEvent|EPZWebViewCreateWindowEvent]]
-
==== getConfigurationsCursor ====
+
:* [[Mobile_SDK_Android:_EPZWebViewOnPageFinishedEvent|EPZWebViewOnPageFinishedEvent]]
-
<pre>
+
:* [[Mobile_SDK_Android:_EPZWebViewOnPageStartedEvent|EPZWebViewOnPageStartedEvent]]
-
public Cursor getConfigurationsCursor()
+
-
</pre>
+
-
A convenience method that returns a cursor with all configurations. This method may prove to be helpful if you are building a list of all configurations to present to a user, where you can use this Cursor along with a CursorAdapter to set your list adapter. Alternatively, you can create a cursor or similar object manually by looping through all promo configuration keys and retrieving configurations via the [[#promotionConfigurationForKey|promotionConfigurationForKey]] method.
+
-
 
+
-
=== EPZListener Implementation Methods ===
+
-
 
+
-
==== promotionConfigurationsRetrieved ====
+
-
<pre>
+
-
public abstract void promotionConfigurationsRetrieved(String[] promoKeys)
+
-
</pre>
+
-
Called when promotion configurations are successfully retrieved.
+
-
 
+
-
<b>Returns</b><br />
+
-
An array of promotion configuration keys.
+
-
 
+
-
<i>Note: This array may be empty, if no current promotions are found for the specified client key. You will be responsible for incorporating logic to determine array length, and add functionality to your app to handle the various scenarios of array length.</i>
+
-
 
+
-
 
+
-
==== promotionConfigurationsFailedWithError ====
+
-
<pre>
+
-
public abstract void promotionConfigurationsFailedWithError(Exception error)
+
-
</pre>
+
-
Called when promotion configurations were not successfully retrieved.
+
-
 
+
-
<b>Returns</b><br />
+
-
An exception, which contains details on the error.
+
-
 
+
-
<i>Note: If the error is due to a lack of Internet connectivity, you will need to take appropriate actions to attempt to retrieve promotion configurations again, as the SDK does not automatically attempt to do so.</i>
+
-
 
+
-
 
+
-
==== webViewDidFireEvent ====
+
-
<pre>
+
-
public abstract void webViewDidFireEvent(String eventName, JSONObject data)
+
-
</pre>
+
-
Called when when the SDK's web view catches an event from the web page.
+
-
 
+
-
<b>Returns</b><br />
+
-
An event name (String), and a JSONObject of data passed along with the event (may be null).
+
-
 
+
-
<i>Note: This method is not presently implemented or called from anywhere within the SDK, but is in place for future releases that will allow full support for website-to-SDK communication.</i>
+
-
 
+
-
==== promoWebViewDidClose ====
+
-
<pre>
+
-
public abstract void promoWebViewDidClose()
+
-
</pre>
+
-
Called when when the SDK's web view closes.
+
-
 
+
-
 
+
-
==== pushPreferencesViewDidClose ====
+
-
<pre>
+
-
public abstract void pushPreferencesViewDidClose()
+
-
</pre>
+
-
Called when when the SDK's push preference view controller closes.
+
-
 
+
-
<i>Note: This method is not presently in use, but is in place for future releases including push notification support.</i>
+
-
 
+
-
== Class Documentation: EPZPromoConfiguration ==
+
-
 
+
-
=== Overview ===
+
-
The EPZPromoConfiguration class stores all necessary information specific to a promotion. You can use an instance of this class to gain access to all of the applicable pieces of information you’ll need for reference, display, and functionality.
+
-
 
+
-
=== Public Methods ===
+
-
 
+
-
==== getConfigKey ====
+
-
<pre>
+
-
public String getConfigKey()
+
-
</pre>
+
-
Returns the configuration's key. This key is used to pass in to various methods, such as the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] [[#launchPromotionForKey|launchPromotionForKey()]] method.
+
-
 
+
-
 
+
-
==== getConfigType ====
+
-
<pre>
+
-
public String getConfigType()
+
-
</pre>
+
-
Returns the promotion’s configuration type. As of version 1.0, the only value for this property is “mobileSdkV1”. This property serves little value outside of the core SDK logic.
+
-
 
+
-
 
+
-
==== getDisplayURL ====
+
-
<pre>
+
-
public String getDisplayURL()
+
-
</pre>
+
-
Returns the promotion’s URL, targeted for display. For instance, if a promotion uses a vanity URL, the vanity URL can be the value for this property. Similarly, if a promotion URL has query parameters attached to the URL that are not intended for display, this value may crop off the parameters, resulting in a URL that is more pleasing to the eye.
+
-
 
+
-
 
+
-
==== getEndpointURL ====
+
-
<pre>
+
-
public String getEndpointURL()
+
-
</pre>
+
-
Returns the promotion’s full URL. Unlike the display URL, this value may include additional URL information such as query parameters, or a URL that is masked by a vanity URL.
+
-
 
+
-
 
+
-
==== getPromoTitle ====
+
-
<pre>
+
-
public String getPromoTitle()
+
-
</pre>
+
-
Returns the promotion's title.
+
-
 
+
-
 
+
-
==== getAssetURLs ====
+
-
<pre>
+
-
public Map<String, String> getAssetURLs()
+
-
</pre>
+
-
Returns a Map of the promotion’s asset URLs, as configured in the ePrize Configuration Service.
+
-
 
+
-
<b>Important Note:</b> There are no set or default key values for this property, as all asset URLs are the responsibility of the party who configures the promotion in the ePrize Configuration Service. As such, if you choose to use asset URLs, it is recommended to do conditional checks for the existence of any map keys you attempt to use, to avoid null values and/or crashes.
+
-
 
+
-
 
+
-
==== getOpenInNativeBrowser ====
+
-
<pre>
+
-
public Boolean getOpenInNativeBrowser()
+
-
</pre>
+
-
Returns a flag alerting whether the site is intended to launch in a device’s native browser. If true, the promotion will launch in the device's native browser rather than in the built-in EPZPromoWebViewController. This logic is handled automatically by the SDK in the [[#launchPromotionForKey|launchPromotionForKey()]] method.
+
-
 
+
-
 
+
-
==== getEndDate ====
+
-
<pre>
+
-
public Date getEndDate()
+
-
</pre>
+
-
Returns the promotion’s end date. If you would like to know and/or display the end date for a promotion, you can use this property to get the value, and then use it as necessary.
+
-
 
+
-
 
+
-
==== getLaunchDate ====
+
-
<pre>
+
-
public Date getLaunchDate()
+
-
</pre>
+
-
Returns the promotion’s launch date. If you would like to know and/or display the launch date for a promotion, you can use this property to get the value, and then use it as necessary.
+

Current revision

Contents

OS Support

The HelloWorld Mobile SDK is built for Android apps targeting API level 14 and higher.

Version & Release Notes

SDK Version: 2.0.6

Release Notes:

  • Updates to dependent librarys
  • Switch to Retrofit + RxJava
Note on naming: You will notice that the SDK uses the historical company name “ePrize” in the framework name, and “EPZ” for the class namespace. Future releases of the SDK may include updates to these names and namespaces to reflect the new company name, HelloWorld, which was introduced in 2014.

Key Concepts

Singleton Classes

The SDK includes a number of Singleton classes which you will not create instances of, but rather, can simply reference via the class' getInstance() method. The Singleton classes used in the SDK include:

Additionally, the SDK includes a class named EPZConstants, which is a simple storage class for constants defined for use in the SDK, and as a convenience for applications using the SDK, so they can make use of the constants as needed (e.g. to avoid typos in string values, to use when defining map keys for configuration options, etc).

Event Dispatching

Version 2.0 of this SDK includes a major shift in the callback logic used for events. Where version 1.0 used listeners as the primary method of implementing callbacks from the SDK, version 2.0 introduces the use of the Event Bus by Otto, which the SDK uses to post events. Your app simply needs to register with the EPZBusProvider and subscribe to whichever events are applicable for your needs.

Configuration Keys

The SDK uses a concept of configuration keys to access data about promotions and instantiate certain views. Each active promotion will have an associated configuration key. When the list of active promotions is retrieved, you will have access to an array of these configuration keys. You will use the keys to get access to specific promotion configurations (EPZPromoConfiguration). The array of keys is stored in the EPZPromoLibrary instance for access anywhere in your application.

Getting Started

The SDK is designed to be an easy and practical way to retrieve a list of active promotions your organization is running with HelloWorld, Inc. Once you retrieve a list of active promotions, you can use the SDK to launch a given promotion using an instance of the SDK's built-in web view controller, where the specified promotion will be loaded into a customizable web view and presented to the user - all while remaining in your mobile application.

Please note: Using this SDK requires a valid client key provided by HelloWorld. If you do not have a client key, please contact your account team or Producer.

Obtain the EPrizeMobileSDK

Please contact your account team or Producer to obtain your copy of the SDK.

Add EPrizeMobileSDK to your project's references

Gradle Project Setup

  1. Copy the "HelloWorld_MobileSDK-X.X.aar" into your projects "libs" folder, where "X.X" represents the latest version of the library.
  2. Make sure your build.gradle file for your project's main module includes the following in addition to the standard Android application Gradle file setup:
  3. repositories {
        mavenCentral()
    
        // add this for use with MobileSDK
        flatDir {
            dirs 'libs'
        }
    }
    
    def mSdkVersion = '2.0'
    
    android {
        compileSdkVersion 24
        buildToolsVersion '27.0.3'
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    dependencies {
        impllementation "com.eprize.mobile.eprizemobilesdk:HelloWorld_MobileSDK:$mSdkVersion@aar"
       
        implementation 'com.squareup:otto:1.3.8' // MobileSDK dependency
        implementation 'com.google.code.gson:gson:2.8.5' // MobileSDK dependency
        implementation 'com.squareup.retrofit2:retrofit:2.4.0' // MobileSDK dependency
        implementation 'com.squareup.retrofit2:converter-gson:2.4.0' // MobileSDK dependency
        implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0' // MobileSDK dependency
        implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' // MobileSDK dependency
        implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' // MobileSDK dependency
        implementation "io.reactivex.rxjava2:rxjava:2.1.16" // MobileSDK dependency
    }
    

    where "$mSdkVersion" corresponds to the version of the library used.

Import SDK classes as necessary

In any class file that needs to utilize the SDK, you will need to import the necessary files. You can consult the Class Documentation section below for more information about each of the classes included in the SDK.

Submit Required Information to HelloWorld

Once you have your project set up in the Google Developers Console as specified above, you will need to submit the following app information to your HelloWorld account team or Producer:

  • App Package (e.g. com.helloworld.mobilesdk.android.demo) - See note below
  • App Name (e.g. MobileSDK Demo App)

Sample Integration

The following section outlines steps to get up and running with the EPrizeMobileSDK in your app. These steps provide small code snippets that you can use as reference in your own project. If you need more information about any of the classes, properties, and/or methods used in any of these snippets, please consult the applicable class documentation provided.

Update your app's Manifest file

To be able to utilize this SDK, you will need to make a few updates to your app's manifest file.

Set up permissions (if not already included):

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Include the SDK's built-in activities in the list of activities:

<activity android:name="com.eprize.mobile.eprizemobilesdk.EPZPromoWebViewController"
          android:configChanges="orientation|keyboardHidden|screenSize" />
Important Note: It is highly recommended that you set the android:configChanges attribute as specified above. This will ensure that the activity is not completely destroyed and re-created when the device's orientation changes, or when the keyboard is hidden. If this is not done, and the activity is destroyed and re-created, the user will lose their place in the promotion they are visiting, and be returned to the promo's home page, resulting in an unpleasant user experience. Additionally, if you wish to lock the activity's orientation to match your app, you can set the android:screenOrientation attribute accordingly.

Configure the EPZPromoLibrary and Register with Event Bus

To use the EPZPromoLibrary , you need to configure them to your needs. You will create a Map (String, Object) that you will pass in to the class' configure() method. You will also need to set up the register and unregister methods with the EPZBusProvider instance in preparation for subscribing to events.

The code sample below includes only the required key/value pairs for the configuration options Map, which utilize constant values found in the EPZConstants class. There are a handful of other key/value pairs you can configure, which are outlined further in the Class Documentation for each class, respectively.

private static final String CLIENT_KEY_PUBLIC = "dev_multi";
private final EPZPromoLibrary mLibrary = EPZPromoLibrary.getInstance();
private final Bus mBus = EPZBusProvider.getInstance();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    // Register with EPZBusProvider so we can subscribe to EPZ events.
    mBus.register(this);
    
    // Set configuration options. 
    Map<String, Object> configOptions = new HashMap<String, Object>();
    configOptions.put(EPZConstants.CONFIG_KEY_CLIENT_KEY, CLIENT_KEY_PUBLIC);
    configOptions.put(EPZConstants.CONFIG_KEY_APP_CONTEXT, this);
    
    // Configure library .
    try {
        mLibrary.configure(configOptions);
    } catch (Exception configException) {
        // Handle exception as needed.
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mBus.unregister(this);
}

Fetch Promotion Configurations and Subscribe to Events

Once you have configured the EPZPromoLibrary, you are safe to fetch the promotion configurations via the fetchPromotionConfigurations() method.

mLibrary.fetchPromotionConfigurations();

You will also need to set up a @Subscribe method to handle the EPZPromotionConfigurationFetchEvent dispatched on completion of fetching the configurations.

@Subscribe
public void handlePromotionConfigurationFetchEvent(EPZPromotionConfigurationFetchEvent event) {
    if (event.error == null) {
        // Successfully retrieved promotion configurations.
    } else {
        // There was an error fetching configurations - handle as needed.
    }
}


Launching a Promotion

If you have at least one active promotion configuration to which you give an accompanying call-to-action, you’ll need a way to display the promotion site in your app. To do so, get a reference to one of the EPZPromoConfiguration objects and call one of the launch methods in the EPZPromoLibrary.

If you do not wish to use the SDK's built-in EPZPromoWebViewController, you can use the SDK's EPZWebViewFragment in your own Activity. For more information on using your own Activity, visit the EPZWebViewFragment page.
if (mLibrary.getPromoKeys() != null && mLibrary.getPromoKeys().length > 0) {
    EPZPromoConfiguration firstConfig = mLibrary.promotionConfigurationForKey(mLibrary.getPromoKeys()[0]);
    mLibrary.launchPromotionForKey(firstConfig.getConfigKey());
}

If you would like to handle any web view or lifecycle events, you can set up a @Subscribe method for the EPZPromoWebViewEvent and/or the EPZPromoWebViewLifecycleEvent.

@Subscribe
public void handlePromoWebViewEvent(EPZPromoWebViewEvent event) {
    // Handle the event fired from the web view here as needed. Event name found via event.eventName
}
@Subscribe
public void handlePromoWebViewLifecycleEvent(EPZPromoWebViewLifecycleEvent event) {
    // Handle lifecycle events as needed. Event name found via event.eventName
    if (event.error != null) {
        // Handle error as needed.
    }
}

Class Documentation

The SDK includes a number of available classes, whose specific documentation pages can be accessed by clicking one of the links below.

com.eprize.mobile.eprizemobilesdk

com.eprize.mobile.eprizemobilesdk.events

Personal tools