Modify the SDK initialization control for alternate Android integration

The Android SDK requires use of the MceApplication class or a class that extend it as the application class of the application. This causes the SDK to start when the application starts, and there is a way to avoid it. A different application class can be used, and it can call the SDK init method to start the SDK. If this is done, no SDK call can be made before the SDK init method is called. The SDK init method also allows a callback object that can be called in the following SDK initialization stages:

  • When the manifest metadata is loaded, the object receives the metadata object.
  • When a notification action is loaded, the object receives the action JSON object.
  • Right after the SDK start is called, the object receives the appkey, senderId, sessionEnabled, sessionDuration, loglevel, and log to file parameters.

📘

Note:

The SDK init method is not supported for versions 3.8.3, 3.8.4, 3.8.5, and 3.8.6.

Here is how you do it with MceSdkConfiguration class:

public class SampleApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        String appKey = "<YOUR APP KEY>";
        MceSdkConfiguration mceSdkConfiguration = new MceSdkConfiguration(appKey);

        mceSdkConfiguration.setBaseUrl("<YOUR BASE URL>");

        mceSdkConfiguration.setMessagingService(MceSdkConfiguration.MessagingService.fcm);
        mceSdkConfiguration.setGroupNotificationsByAttribution(true);

        mceSdkConfiguration.setLogBufferSize(10);
        mceSdkConfiguration.setLogFile(true);
        mceSdkConfiguration.setLogIterationDurationInHours(1);
        mceSdkConfiguration.setLogLevel(Logger.LogLevel.error);

        mceSdkConfiguration.setMetricTimeInterval(300);

        mceSdkConfiguration.setSessionsEnabled(true);
        mceSdkConfiguration.setSessionTimeout(20);
        mceSdkConfiguration.setUseFileImageCache(true);
        mceSdkConfiguration.setUseInMemoryImageCache(true);
        mceSdkConfiguration.setFileImageCacheCapacityInMB(200);
        mceSdkConfiguration.setInMemoryImageCacheCapacityInMB(20);


        MceSdkConfiguration.LocationConfiguration.SyncConfiguration syncConfiguration = mceSdkConfiguration.getLocationConfiguration().getSyncConfiguration();

        syncConfiguration.setLocationResponsiveness(300);
        syncConfiguration.setSyncInterval(300);
        syncConfiguration.setSyncRadius(100000);
        syncConfiguration.setMinLocationsForSearch(1);
        syncConfiguration.setMaxLocationsForSearch(20);

        MceSdkConfiguration.LocationConfiguration.IBeaconConfiguration iBeaconConfiguration = mceSdkConfiguration.getLocationConfiguration().getiBeaconConfiguration();
        iBeaconConfiguration.setUuid("<YOUR UUID>");
        iBeaconConfiguration.setBeaconForegroundScanDuration(5);
        iBeaconConfiguration.setBeaconForegroundScanInterval(30);
        iBeaconConfiguration.setBeaconBackgroundScanDuration(30);
        iBeaconConfiguration.setBeaconBackgroundScanInterval(300);


        MceApplication.init(this, mceSdkConfiguration, new SdkInitLifecycleCallbacks() {
            @Override
            public void handleMetadata(Bundle bundle) {

            }

            @Override
            public void onPluginMessageProcessorLoad(JSONObject jsonObject) {

            }

            @Override
            public void onPluginActionLoad(JSONObject jsonObject) {

            }

            @Override
            public void onPluginNotificationTypeLoad(JSONObject jsonObject) {

            }

            @Override
            public void onStart(MceSdkConfiguration mceSdkConfiguration) {

            }

            @Override
            public void onSdkReinitializeNeeded(Context context) {

            }
        });
    }

}