Skip to content

Latest commit

 

History

History
645 lines (424 loc) · 12.5 KB

api-reference.md

File metadata and controls

645 lines (424 loc) · 12.5 KB

Mobile Core API Usage

This document lists the APIs provided by MobileCore, along with sample code snippets on how to properly use the APIs.

For more in-depth information about the Mobile Core, visit the official SDK documentation on Mobile Core.

Importing Mobile Core

Java
import com.adobe.marketing.mobile.MobileCore;
Kotlin
import com.adobe.marketing.mobile.MobileCore

Getting MobileCore version

Java
final String coreVersion = MobileCore.extensionVersion();
Kotlin
val coreVersion: String = MobileCore.extensionVersion()

Setting the log level

The SDK log verbosity can be adjusted to one of the following modes: ERROR, WARNING, DEBUG, VERBOSE.

Java
MobileCore.setLogLevel(LoggingMode.VERBOSE);
Kotlin
MobileCore.setLogLevel(LoggingMode.VERBOSE)

Retrieving the current log level

Java
final LoggingMode loggingMode = MobileCore.getLogLevel();
Kotlin
val loggingMode: LoggingMode = MobileCore.getLogLevel()

Setting the wrapper type

The wrapper type can be set to one of the follwing types: NONE, REACT_NATIVE, FLUTTER, CORDOVA, UNITY, XAMARIN.

Java
MobileCore.setWrapperType(WrapperType.REACT_NATIVE);
Kotlin
MobileCore.setWrapperType(WrapperType.REACT_NATIVE)

Setting Android Application instance

Use the setApplication api to pass the Android Application instance to SDK. This allows the SDK to monitor the lifecycle of your Android application.

Java
public class YourApp extends Application {

   @Override
   public void onCreate() {
      super.onCreate();

      MobileCore.setApplication(this);
   }
}
Kotlin
class YourApp : Application() {
    override fun onCreate() {
        super.onCreate()

        MobileCore.setApplication(this)
    }
}

Retrieving the Android Application instance

You can use the getApplication() api to get the Android Application instance that was previously set via MobileCore.setApplication()

Java
final Application app = MobileCore.getApplication();
Kotlin
val app = MobileCore.getApplication()

Initializing the SDK by automatically registering all extensions and enabling Lifecycle data collection

Note

API initialize(String appId) added since Core 3.3.0

Important

All Adobe Mobile SDK extensions listed as a dependency in your application are automatically registered when calling initialize(String appId).

Automatic Lifecycle data collection requires Lifecycle extension included as an app dependency.

Java
public class YourApp extends Application {

   @Override
   public void onCreate() {
      super.onCreate();

      MobileCore.initialize(this, YOUR_APP_ID);
      
      // Optionally, if you need a callback:
      // MobileCore.initialize(this, YOUR_APP_ID, , new AdobeCallback<Void>() {
      //   @Override
      //   public void call(Void result) {
      //      // SDK initialized.
      //   }
      // });
   }
}
Kotlin
class YourApp : Application() {
    override fun onCreate() {
        super.onCreate()

        MobileCore.initialize(this, YOUR_APP_ID)
        
        // Optionally, if you need a callback:
        // MobileCore.initialize(this, YOUR_APP_ID) { 
        //     // SDK initialized.
        // }
    }
}

Initializing the SDK by automatically registering all extensions while disabling Lifecycle data collection

Note

API initialize(InitOptions options) added since Core 3.3.0

Important

All Adobe Mobile SDK extensions listed as a dependency in your application are automatically registered when calling initialize(InitOptions options).

Java
public class YourApp extends Application {

   @Override
   public void onCreate() {
      super.onCreate();

      InitOptions options = InitOptions.configureWithAppID("YOUR_APP_ID");
      options.setLifecycleAutomaticTrackingEnabled(false);

      MobileCore.initialize(this, options, new AdobeCallback<Void>() {
         @Override
         public void call(Void result) {
            // SDK initialized.
         }
      });
   }
}
Kotlin
class YourApp : Application() {
    override fun onCreate() {
        super.onCreate()

        val options = InitOptions.configureWithAppID("YOUR_APP_ID").apply {
            lifecycleAutomaticTrackingEnabled = false
         }

        MobileCore.initialize(this, options) {
            // SDK initialized.
        }
    }
}

Manually registering extensions and starting the SDK

Java
import com.adobe.marketing.mobile.Identity
import com.adobe.marketing.mobile.Signal
...

MobileCore.registerExtensions(
    Arrays.asList(Identity.EXTENSION, Signal.EXTENSION, ...), new AdobeCallback<Object>() {
    // handle callback
});
Kotlin
import com.adobe.marketing.mobile.Identity
import com.adobe.marketing.mobile.Signal
...

MobileCore.registerExtensions(Arrays.asList(Identity.EXTENSION, Signal.EXTENSION, ...)){
    // handle callback
}

Registering an EventListener

Java
MobileCore.registerEventListener(EventType.ANALYTICS, EventSource.REQUEST_CONTENT, new AdobeCallback<Event>() {
    @Override
    public void call(Event value) {
        // handle callback
    }
});
Kotlin
MobileCore.registerEventListener(EventType.ANALYTICS, EventSource.REQUEST_CONTENT) { event ->
    // handle callback
}

Configuring the SDK with an app id

MobileCore.configureWithAppId api can be used to download and apply the configuration for the provided app Id.

Java
MobileCore.configureWithAppId("YOUR_APP_ID");
Kotlin
MobileCore.configureWithAppId("YOUR_APP_ID")

Configuring the SDK with a bundled file asset

You can bundle a JSON configuration file in the app's assets folder to replace or complement the configuration that was downloaded by using the Configure with App ID per environment approach.

Java
MobileCore.configureWithFileInAssets("SampleBundledJSONConfigFile.json");
Kotlin
MobileCore.configureWithFileInAssets("SampleBundledJSONConfigFile.json")

Configuring the SDK with a file path

Java
MobileCore.configureWithFileInPath("absolute/path/to/YourJSONConfigfile.json");
Kotlin
MobileCore.configureWithFileInPath("absolute/path/to/YourJSONConfigfile.json")

Updating the configuration programmatically

You can update the configuration programmatically by passing configuration keys and values to override the existing configuration via MobileCore.updateConfiguration() api Keys that are not found on the current configuration are added when this method is followed. Null values are allowed and replace existing configuration values.

Java
Map<String, Object> data = new HashMap<>();
data.put("global.privacy", "optedout");

MobileCore.updateConfiguration(data);
Kotlin
val data: Map<String, Any?> = mapOf(
    "global.privacy" to "optedout",
    "sampleKey" to "sampleValue"
)

MobileCore.updateConfiguration(data)

Clearing programmatically updated configuration

You can clear programmatic configuration changes made using MobileCore.updteConfiguration() api via MobileCore.clearUpdatedConfiguration() api.

Java
MobileCore.clearUpdatedConfiguration();
Kotlin
MobileCore.clearUpdatedConfiguration()

Dispatch an Event

Java
final Map<String, Object> eventData = new HashMap<>();
eventData.put("sampleKey", "sampleValue");

final Event sampleEvent = new Event.Builder("SampleEventName", "SampleEventType", "SampleEventSource")
                          .setEventData(eventData)
                          .build();

MobileCore.dispatchEvent(sampleEvent);
Kotlin
val eventData: Map<String, Any?> = mapOf("sampleKey" to "sampleValue")

val sampleEvent = Event.Builder("Sample Event Name", "Sample EventType", "Sample Event Source")
                  .setEventData(eventData)
                  .build()

MobileCore.dispatchEvent(sampleEvent)

Dispatch an Event with response callback

Java
final Map<String, Object> eventData = new HashMap<>();
eventData.put("sampleKey", "sampleValue");

final Event sampleEvent = new Event.Builder("SampleEventName", "SampleEventType", "SampleEventSource")
                          .setEventData(eventData)
                          .build();

MobileCore.dispatchEventWithResponseCallback(sampleEvent, 5000L, new AdobeCallbackWithError<Event>() {
    // implement callback
});
Kotlin
val eventData: Map<String, Any?> = mapOf("sampleKey" to "sampleValue")
val sampleEvent = Event.Builder("SampleEventName", "SampleEventType", "SampleEventSource")
                       .setEventData(eventData)
                       .build()

MobileCore.dispatchEvent(sampleEvent, 5000L) {
    // implement callback
}

Setting an advertising identifier

Java
MobileCore.setAdvertisingIdentifier("YOUR_ADVERTISING_IDENTIFIER");
Kotlin
MobileCore.setAdvertisingIdentifier("YOUR_ADVERTISING_IDENTIFIER")

Setting a push identifier

Java
MobileCore.setPushIdentifier("YOUR_PUSH_IDENTIFIER");
Kotlin
MobileCore.setPushIdentifier("YOUR_PUSH_IDENTIFIER")

Collecting PII data

Java
final Map<String, String> piiData = new HashMap<>();
piiData.put("piiDataKey", "piiDataValue");

MobileCore.collectPii(piiData);
Kotlin
val piiData: Map<String, Any?> = mapOf("piiDataKey" to "sampleValue")
MobileCore.collectPii(piiData)

Collecting Message info

Java
final Map<String, Object> messageInfo = new HashMap<>();
messageInfo.put("sampleKey", "sampleValue");

MobileCore.collectMessageInfo(messageInfo);
Kotlin
val messageInfo: Map<String, Any?> = mapOf("sampleKey" to "sampleValue")

MobileCore.collectMessageInfo(messageInfo)

Setting privacy status

Privacy status can be set to one of the following values OPT_IN, OPT_OUT, UNKNOWN.

Java
MobileCore.setPrivacyStatus(MobilePrivacyStatus.OPT_IN);
Kotlin
MobileCore.setPrivacyStatus(MobilePrivacyStatus.OPT_IN)

Retrieving current privacy status

Java
MobileCore.getPrivacyStatus(new AdobeCallback<MobilePrivacyStatus>() {
    @Override
    public void call(MobilePrivacyStatus privacyStatus) {
        // handle callback
    }
});
Kotlin
MobileCore.getPrivacyStatus{ privacyStatus ->
    // handle callback
}

Reading the SDK identities

Java
MobileCore.getSdkIdentities(new AdobeCallback<String>() {
    @Override
    public void call(String sdkIdentitiesJson) {
        // handle callback
    }
});
Kotlin
MobileCore.getSdkIdentities { sdkIdentitiesJson -> 
    // handle callback
}

Reset SDK identities

Java
MobileCore.resetIdentities();
Kotlin
MobileCore.resetIdentities()

Track an action

Java
final Map<String, String> sampleContextData = new HashMap<>();
messageInfo.put("sampleKey", "sampleValue");

MobileCore.trackAction("SampleActionName", sampleContextData);
Kotlin
val sampleContextData: Map<String, String?> = mapOf("sampleKey" to "sampleValue")
MobileCore.trackAction("SampleActionName", sampleContextData)

Track state

Java
final Map<String, String> sampleContextData = new HashMap<>();
messageInfo.put("sampleKey", "sampleValue");

MobileCore.trackState("SampleState", sampleContextData);
Kotlin
val sampleContextData: Map<String, String?> = mapOf("sampleKey" to "sampleValue")
MobileCore.trackAction("SampleState", sampleContextData)

Starting a Lifecycle session

Java
final Map<String, String> sampleContextData = new HashMap<>();
messageInfo.put("sampleKey", "sampleValue");

MobileCore.lifecycleStart(sampleContextData);
Kotlin
val sampleContextData: Map<String, String?> = mapOf("sampleKey" to "sampleValue")
MobileCore.lifecycleStart(sampleContextData)

Pausing a Lifecycle session

Java
MobileCore.lifecyclePause();
Kotlin
MobileCore.lifecyclePause()