Configuration Methods

Here is the list of methods that are provided by the Android library.

This section contains the following information:

Initial Configuration

The following method must be called once in the onCreate method of your main activity:

Method Description
setContext

For example:

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  Config.setContext(this.getApplicationContext());
}

SDK Settings (Config Class)

Method Description
registerAdobeDataCallback

Registers an object that implements the AdobeDataCallback interface. The overwritten "call" method will be invoked with a Config.MobileDataEvent value and the associated data in a Map<String, Object> for the triggering event. For more details about which events will trigger this callback, see MobileDataEvent Enum.

Tip: This method requires version 4.9.0 or later.

Syntax:

public static void registerAdobeDataCallback(final AdobeDataCallback callback);

Example:

Config.registerAdobeDataCallback(new Config.AdobeDataCallback() {
    @Override
    public void call(Config.MobileDataEvent event, Map<String, Object> contextData) {
        // handle each event type accordingly
        if (event == Config.MobileDataEvent.MOBILE_EVENT_ACQUISITION_INSTALL) {
            // do something with acquisition data found in contextData parameter
            HashMap<String, Object> acquisitionData = new HashMap<String, Object>(contextData);
            ...
        }
    }
});
getVersion

Returns the current version of the Adobe Mobile library.

Syntax:

public static String getVersion();

Example:

String libraryVersion = Config.getVersion();
getPrivacyStatus

Returns the enum representation of the privacy status for current user.

Here are the privacy status values:

  • MOBILE_PRIVACY_STATUS_OPT_IN, where the hits are sent immediately.
  • MOBILE_PRIVACY_STATUS_OPT_OUT, where the its are discarded.
  • MOBILE_PRIVACY_STATUS_UNKNOWN, where if your report suite is timestamp enabled, hits are saved until the privacy status changes to opt-in (hits are sent) or opt-out (hits are discarded).

    If your report suite is not timestamp enabled, hits are discarded until the privacy status changes to opt in.

The default value is set in the ADBMobileConfig.json file.

Syntax:

public static MobilePrivacyStatus getPrivacyStatus();

Example:

MobilePrivacyStatus privacyStatus = Config.getPrivacyStatus();
setPrivacyStatus

Sets the privacy status for the current user to status.

You can set the privacy status to one of the following values:

  • MOBILE_PRIVACY_STATUS_OPT_IN, where the hits are sent immediately.

    These hits are sent immediately.

  • MOBILE_PRIVACY_STATUS_OPT_OUT, where the its are discarded.

    These hits are discarded.

  • MOBILE_PRIVACY_STATUS_UNKNOWN, where if your report suite is timestamp enabled, hits are saved until the privacy status changes to opt-in (hits are sent) or opt-out (hits are discarded).

    If your report suite is not timestamp enabled, hits are discarded until the privacy status changes to opt in.

Syntax:

public static void setPrivacyStatus(MobilePrivacyStatus status);

Example:

Config.setPrivacyStatus(MobilePrivacyStatus.MOBILE_PRIVACY_STATUS_OPT_IN);
getLifetimeValue

Returns the lifetime value of the current user.

The default value is 0.

Syntax:

public static BigDecimal getLifetimeValue();

Example:

BigDecimal currentLifetimeValue = Config.getLifetimeValue();
getUserIdentifier

If a custom identifier has been set, the custom user identifier is returned. If a custom identifier has not been set, it returns null.

The default value is null.

Tip: If your app upgrades from the Experience Cloud 3.x to the 4.x SDK, the previous custom or automatically generated visitor ID is retrieved and stored as the custom user identifier. This preserves visitor data between SDK upgrades. For new installations on the 4.x SDK, until it is set, the user identifier is null.

Syntax:

public static String getUserIdentifier();

Example:

String userId = Config.getUserIdentifier();
setUserIdentifier

Sets the user identifier to identifier.

Syntax:

public static void setUserIdentifer(String identifier);

Example:

Config.setUserIdentifier("billybob");
getDebugLogging

Returns the current debug logging preference.

The default value is false.

Syntax:

public static Boolean getDebugLogging();

Example:

Boolean debugging = Config.getDebugLogging();
setDebugLogging

Sets the debug logging preference to debugLogging.

Syntax:

public static void setDebugLogging(Boolean debugLogging);

Example:

Config.setDebugLogging(true);
collectLifecycleData

Indicates to the SDK that lifecycle data should be collected for use across all solutions in the SDK. For more information, see Lifecycle Metrics.

Syntax:

public static void collectLifecycleData(final Activity activity, final Map<String, Object> contextData);

Example:

Without extra context data:

@Override
protected void onResume() {
   super.onResume();
   Config.collectLifecycleData(this);
}

With extra context data:

@Override
public void onResume() {
    HashMap<String, Object> contextData = new HashMap<String, Object>();
    contextData.put("myapp.category", "Game");
    Config.collectLifecycleData(this, contextData);
}
collectLifecycleData (Activity activity)

(Version 4.2 or later) Indicates to the SDK that lifecycle data should be collected for use across all solutions in the SDK. For more information, see Lifecycle Metrics.

Syntax:

public static void collectLifecycleData(final Activity activity);

Example:

@Override
protected void onResume() {
	super.onResume();
	// assumes being called in an Activity class
	Config.collectLifecycleData(this);
}
pauseCollecting​LifecycleData

Indicates to the SDK that your app is paused, so that lifecycle metrics are calculated correctly. For example, onPause collects a timestamp to determine the previous session length. This also sets a flag so that lifecycle knows that the app did not crash. For more information, see Lifecycle Metrics.

Syntax:

public static void pauseCollectingLifecycleData();

Example:

@Override
protected void onPause() {
   super.onPause();
   Config.pauseCollectingLifecycleData();
}
setSmallIconResourceId(int resourceId)

(Version 4.2 or later) Sets the small icon that will be used for notifications that were created by the SDK. This icon will appear in the status bar and will be the secondary image that is displayed when the user sees the complete notification in the notification center.

Syntax:

public static void setSmallIconResourceId(final int resourceId);

Example:

Config.setSmallIconResourceId(R.drawable.appIcon);
setLargeIconResourceId(int resourceId)

(Version 4.2 or later) Sets the large icon that will be used for notifications that were created by the SDK. This icon will be the primary image that is displayed when the user sees the complete notification in the notification center.

Syntax:

public static void setLargeIconResourceId(final int resourceId);

Example:

Config.setLargeIconResourceId(R.drawable.appIcon);
overrideConfigStream(InputStream configInput)

(Version 4.2 or later) Allows you to load a different ADBMobile JSON config file when the application starts. The different configuration is used until the application is closed.

Syntax:

public static void overrideConfigStream(final InputStream configInput);

Example:

 try {
	InputStream configInput = getAssets().open("ExampleJSONFile.json");
	Config.overrideConfigStream(configInput);
	} catch (IOException ex) {
	// do something with the exception if needed
}
setPushIdentifier

Sets the device token for push notifications.

Syntax:

public static void setPushIdentifier(final String registrationId);

Example:

...
// note: the code to retreive the push token must run in the background
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
String token = instanceID.getToken("835015092242", GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Config.setPushIdentifier(token);
...
submitAdvertisingIdentifierTask

Provides a Callable to the SDK that returns the string of the Advertising Identifier that is returned from Google Play Services.

The SDK runs this task on a background thread and sets an internal variable for the Advertising Identifier that is based on the value returned from the Callable.

Important: If you want to use the Advertising Identifier in Acquisition or Lifecycle, call it before calling Config.collectLifecycleData.

Syntax:

public static void submitAdvertisingIdentifierTask(final Callable<String> task);

Example:

@Override
public void onResume() {
    super.onResume();
 
    final Callable<String> task = new Callable<String>() {
        @Override
        public String call() throws Exception {
            AdvertisingIdClient.Info idInfo;
            String adid = null;
            Context appContext = CLASSNAME.this.getApplicationContext();
 
            try {
                idInfo = AdvertisingIdClient.getAdvertisingIdInfo(appContext);
                if (idInfo != null) {
                    adid = idInfo.getId();
                }
            } catch (Exception ex) {
                Log.e("Error", ex.getLocalizedMessage());
            }
 
            return adid;
        }
    };
 
    Config.submitAdvertisingIdentifierTask(task);
    Config.collectLifecycleData(this);
}

AdobeDataCallback Interface

public interface AdobeDataCallback { 
    void call(MobileDataEvent event, Map<String, Object> contextData); 
} 

MobileDataEvent Enum

public enum MobileDataEvent { 
    MobileDataEvent.MOBILE_EVENT_LIFECYCLE, // triggers on a lifecycle hit 
    MobileDataEvent.MOBILE_EVENT_ACQUISITION_INSTALL, // triggers on a app install that has acquisition data 
    MobileDataEvent.MOBILE_EVENT_ACQUISITION_LAUNCH // triggers on launch when the device previously installed via acquisition 
}