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.
  • The following sample code shows how this can be done:

    import android.app.Application;
    import android.os.Bundle;
    
    import com.ibm.mce.sdk.api.MceApplication;
    import com.ibm.mce.sdk.api.SdkInitLifecycleCallbacks;
    
    import org.json.JSONObject;
    
    public class CustomApplication extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
            // do application init stuff
        }
        
        private void startMceSdk() {
            MceApplication.init(this, new SdkInitLifecycleCallbacks() {
                @Override
                public void handleMetadata(Bundle metadata) {
                    //metadata handling here
                }
    
                @Override
                public void onPluginActionLoad(JSONObject action) {
                    //plugin action handling here
                }
    
                @Override
                public void onStart(String appKey, String appKey1, String senderId, boolean sessionEnabled, int sessionDurationInMinutes, String logLevel, boolean logToFile) {
                    // this will be called right after the sdk start will be called.
                }
            });
        }
    }

    Go Back to the Mobile App Messaging home page.

    Join The Discussion

    Your email address will not be published. Required fields are marked *