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.
Here is how you do it with MceSdkConfiguration class:
[block:code] { "codes": [ { "code": "public class SampleApplication extends Application {\n\n @Override\n public void onCreate() {\n super.onCreate();\n String appKey = \"<YOUR APP KEY>\";\n MceSdkConfiguration mceSdkConfiguration = new MceSdkConfiguration(appKey);\n\n mceSdkConfiguration.setBaseUrl(\"<YOUR BASE URL>\");\n\n mceSdkConfiguration.setMessagingService(MceSdkConfiguration.MessagingService.fcm);\n mceSdkConfiguration.setGroupNotificationsByAttribution(true);\n\n mceSdkConfiguration.setLogBufferSize(10);\n mceSdkConfiguration.setLogFile(true);\n mceSdkConfiguration.setLogIterationDurationInHours(1);\n mceSdkConfiguration.setLogLevel(Logger.LogLevel.error);\n\n mceSdkConfiguration.setMetricTimeInterval(300);\n\n mceSdkConfiguration.setSessionsEnabled(true);\n mceSdkConfiguration.setSessionTimeout(20);\n mceSdkConfiguration.setUseFileImageCache(true);\n mceSdkConfiguration.setUseInMemoryImageCache(true);\n mceSdkConfiguration.setFileImageCacheCapacityInMB(200);\n mceSdkConfiguration.setInMemoryImageCacheCapacityInMB(20);\n\n\n MceSdkConfiguration.LocationConfiguration.SyncConfiguration syncConfiguration = mceSdkConfiguration.getLocationConfiguration().getSyncConfiguration();\n\n syncConfiguration.setLocationResponsiveness(300);\n syncConfiguration.setSyncInterval(300);\n syncConfiguration.setSyncRadius(100000);\n syncConfiguration.setMinLocationsForSearch(1);\n syncConfiguration.setMaxLocationsForSearch(20);\n\n MceSdkConfiguration.LocationConfiguration.IBeaconConfiguration iBeaconConfiguration = mceSdkConfiguration.getLocationConfiguration().getiBeaconConfiguration();\n iBeaconConfiguration.setUuid(\"<YOUR UUID>\");\n iBeaconConfiguration.setBeaconForegroundScanDuration(5);\n iBeaconConfiguration.setBeaconForegroundScanInterval(30);\n iBeaconConfiguration.setBeaconBackgroundScanDuration(30);\n iBeaconConfiguration.setBeaconBackgroundScanInterval(300);\n\n\n MceApplication.init(this, mceSdkConfiguration, new SdkInitLifecycleCallbacks() {\n @Override\n public void handleMetadata(Bundle bundle) {\n\n }\n\n @Override\n public void onPluginMessageProcessorLoad(JSONObject jsonObject) {\n\n }\n\n @Override\n public void onPluginActionLoad(JSONObject jsonObject) {\n\n }\n\n @Override\n public void onPluginNotificationTypeLoad(JSONObject jsonObject) {\n\n }\n\n @Override\n public void onStart(MceSdkConfiguration mceSdkConfiguration) {\n\n }\n\n @Override\n public void onSdkReinitializeNeeded(Context context) {\n\n }\n });\n }\n\n}\n", "language": "java" } ] } [/block]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) { } }); } }
Updated 10 days ago
