Legacy Integration (Deprecated)

We recommend you to switch to the new APIs for better stability, performance and long term support.
These APIs are not complaint with GDPR. If your application runs in the European Union please switch to the new APIs.

SDK Configuration

Adding MoEngage meta tags

Get APP ID from the Settings Page on the MoEngage dashboard and add it to the manifest file as shown below.

<!-- MANDATORY FIELD: APP ID AS SEEN ON MOENGAGE DASHBOARD APP SETTINGS PAGE -->
<meta-data
    android:name="APP_ID"
    android:value="DAO6UGZ73DXXTK7BXX96TPXX" />

Tracking Activity or Adding Lifecycle Callbacks

Add below code in the onCreate() of your application class to enable MoEngage SDK to track Activity states
Note: This API is only available from 7.0.00

MoEHelper.getInstance(getApplicationContext()).autoIntegrate(this);

Alternatively, create a base activity like below , which other activities of your app will extend.If you already have a base activity then simply add the methods in your base activity.

public class BaseActivity extends Activity {
  private MoEHelper mHelper;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHelper = MoEHelper.getInstance(this);
  }

  @Override
  protected void onStart() {
    super.onStart();
    mHelper.onStart(this);
  }

  @Override
  protected void onStop() {
    super.onStop();
    mHelper.onStop(this);
  }

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

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mHelper.onSaveInstanceState(outState);
  }

  @Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mHelper.onRestoreInstanceState(savedInstanceState);
  }
}

Adding meta tags to manifest for push notifications

<!-- MANDATORY FIELD: SENDER ID , i.e. THE PROJECT NUMBER AS MENTIONED ON GOOGLE CLOUD CONSOLE PROJECTS PAGE -->
<meta-data
    android:name="SENDER_ID"
    android:value="id:XXXXXXXXXXXX" />

<!-- MANDATORY FIELD: THE NOTIFICATION SMALL ICON WHICH WILL BE USED TO SET TO NOTIFICATIONS POSTED -->
<meta-data
    android:name="NOTIFICATION_ICON"
    android:value="@drawable/ic_launcher" />

<!-- MANDATORY FIELD: THE NOTIFICATION LARGE ICON WHICH WILL BE USED TO SET TO NOTIFICATIONS POSTED -->
<meta-data
   android:name="NOTIFICATION_LARGE_ICON"
   android:value="@drawable/large_icon" />

Adding meta tags to Skip GCM Registration

<meta-data
    android:name="SKIP_GCM_REGISTRATION"
    android:value="true" />

Showing Multiple Notifications at one go

By default the SDK will update an exiting notification to keep the notification area uncluttered. But you can decide to switch to a mode where the app shows multiple notifications. It can be achieved by adding the following meta tag in the AndroidManifest.xml file.

<!-- OPTIONAL FIELD: THE NOTIFICATION TYPE WHICH WILL BE USED, SINGLE OR MULTIPLE. DEFAULT BEHAVIOR IS SINGLE -->
<meta-data
    android:name="NOTIFICATION_TYPE"
    android:value="@integer/notification_type_multiple" />

Customising Notification tones

By default the SDK uses the default notification tone. This can be customized by adding the following meta tag in the AndroidManifest.xml file.

<!-- OPTIONAL FIELD: THE NOTIFICATION TONE THAT WILL BE USED. IF NOT SET WILL PLAY THE DEFAULT SOUND -->
<meta-data
    android:name="NOTIFICATION_TONE"
    android:value="@raw/[file_name]" />

Setting Notification Color

Lollipop and above only

Define your notification color in a color resource named moe_notification_color as shown below:

<color name="moe_notification_color">[hex code of color]</color>

Note : This would take precedence over "NOTIFICATION_LARGE_ICON"

Opt-out BackStack creation for Notification

You can optout backstack creation for a notification by adding below code in your application class

PushManager.getInstance().optoutBackStackBuilder(true);

Opt-out activity tracking

To opt-out from activity tracking add below meta-data in activity declaration in your manifest file.
Note: This feature is available from SDK version 7.0.00

<activity
    android:name=".SplashScreen"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data
        android:name="OPT_OUT_TRACKING"
        android:value="true"/>
</activity>

Opt-out NavBar

If your app has Navigation Drawer , then add below code in your application class to InApp work properly
Note: This feature is available from SDK version 6.0.29

InAppManager.getInstance().optOutNavBar(this,true);

Opt-out from Location Tracking and GeoFence

Add in your Application Class

MoEHelper.getInstance(getApplicationContext()).optOutOfLocationTracking(true);
MoEHelper.getInstance(getApplicationContext()).optOutOfGeoFences(true);

Alternatively, geofence module can be excluded from the app's dependency list. Alter the dependency as shown below to exclude geofence module.

compile ('com.moengage:moe-android-sdk:9.1.03') {
        exclude group: 'com.moengage', module: 'moe-location-lib'
    }

Opt-out Activity from showing InApp

If you want to suppress the In-APP in a particular activity for e.g., the Payment page or splash screen add the following meta-data to that particular activity in your manifest file

Note: This feature is available from main SDK version 6.0.18

<activity
 android:name="[your_activity]">
  <meta-data
    android:name="showInApp"
    android:value="false" />
</activity>

Opt-out of MoEngage extras in Deeplink

By default MoEngage SDK adds MoEngage extras in the deep-link URL. To get only the deep-link entered on the dashboard use the below opt-out in the Application class's onCreate()

PushManager.getInstance().optOutMoEngageExtras(true);

How to enable MoEngage SDK's debug logs for unsigned builds?

To enable logs for unsigned build add the below line of code in the onCreate() of your Application class.

MoEHelper.getInstance(getApplicationContext()).setLogLevel(Logger.VERBOSE);

How to enable MoEngage SDK's debug logs for signed builds?

To enable logs for signed build add the below lines of code in the onCreate() of your Application class.

MoEHelper.getInstance(getApplicationContext()).setLogLevel(Logger.VERBOSE);
    MoEHelper.getInstance(getApplicationContext()).setLogStatus(true);