1. Home
  2. Integrations
  3. Android Native Integration

Android Native Integration

Install the SDK

Download the latest Android Native SDK

Note: Please refer to the Android SDK Change log for details about the changes/upgrades on the latest SDK version from previous versions.

The mTracktion SDK should contain the following files:

  1. mTractionSDK.jar: This is the main SDK library for integrating your Application.
  2. MTractionSingleInstallReceiver.java: This is a sample file provided to track installs from single tracker.
  3. MTractionMultipleInstallReceivers.java: This is a sample file provided to track installs from multiple tracker.

The step-by-step integration process has been described in detail in the coming sections.

  1. Basic Integration Settings
  2. Installs Tracking
  3. App Session Tracking (Optional)
  4. In App Events Integration (Optional)
  5. CRM Integration – Android SDK

1. Basic Integration Settings

Add mTractionSDK.jar to your project as a project library.

  • If you’re using Eclipse, modify your Java Build Path, and choose Add External JAR.
  • If you’re using the SDK tools directly, drop it into your libs folder and the ant task will pick it up.
  • If you’re using the Android Studio tools directly, drop it into your libs folder ,Right click on it and choose Add as Library option for adding it into project.
  1. Open the AndroidManifest.xml file in your project and add the following:

    <uses-permission android:name=”android.permission.INTERNET” />
    <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>

     

    This is to grant permission to access Internet and Network State.

    Optionally, you can also grant Phone State access (as shown below) for our SDK to receive device IMEI & Network Operator related information of your App Users.  

<uses-permission android:name=”android.permission.READ_PHONE_STATE” />

 

  • Put the following lines of code in the first place of your app run. This must be place it in the onCreate() method of Application.

    MTractionDownloadTracker mTractionDownloadTracker = new MTractionDownloadTracker();
    mTractionDownloadTracker.trackDownload(getApplicationContext(), null);

     

  • To enable Debug logs, the following setting should be enabled.

    <application>
    // mTraction Debug Mode
    <meta-data
    android:name=”mt_DebugMode”
    android:value=”true”/>
    </application>

     

    Note: Please ensure that the mt_DebugMode should be set to “false” before going live.

  • Add google-play-services_ads dependency library into your project module setting.
  • Add google_play_services_version in Project’s Manifest file inside Application tag.

    <application>
    // Application Version
    <meta-data
    android:name=”com.google.android.gms.version”
    android:value=”@integer/google_play_services_version” />
    </application>

     

  • Add the following line to the dependencies section of the build.gradle file for your app:

    dependencies {
        ...
        compile 'com.android.installreferrer:installreferrer:1.0'
    }
    
  • Add the following line to the Top-level build file for your app:

    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }
    

 

2. Installs Tracking

We have provided two different methods to handle download conversions, both single and multiple. Use multiple if you plan to use other methods for download conversion tracking. Choose one of the methods below:

  • Single Install Tracking SDK:
    1. Copy the MTractionSingleInstallReceiver.java file to your applications main Package folder. Change the Package Name at the top of the file, to the package name of the main project.
    2. Open the AndroidManifest.xml file in your project and add the following Receiver settings.

      <receiver android:name=”.MTractionSingleInstallReceiver” android:exported=”true”>
      <intent-filter>
      <action android:name=”com.android.vending.INSTALL_REFERRER” />
      </intent-filter>
      </receiver>

       

    3. Do the following settings in the AndroidManifest.xml under the Application section. The App_Token is provided to you as a part of the Application Registration process on the mTraction Platform.

      <application>
      // mTraction App Token
      <meta-data
      android:name=”appToken”
      android:value=”App_Token”/>
      </application>

       

At this point in time, you can validate your install tracking with our mTraction Testing Applciation. Please refer to this documentation and follow the steps as mentioned: mTraction Android SDK Testing

  • Multiple Installs Tracking SDK:
    1. If your Android app has multiple receivers for INSTALL_REFERRER, you will need to write a custom receiver that will call these receivers.We recommend to use MTractionMultipleInstallReceivers.java class included in SDK suite. Alternatively, you can create your custom class as per the below sample code:
package com.test.sample; //Application Package Name
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.mtraction.mtractiondownloadtracker.MTractionDownloadTracker;

public class MTractionMultipleInstallReceivers extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
 
    // Call MTractionDownloadTracker\
    MTractionDownloadTracker mTractionDownloadTracker = new MTractionDownloadTracker();
    mTractionDownloadTracker.onReceive(context, intent);

    // Initialize and call onReceive for other receivers

}
}
  • Then place the receiver in your AndroidManifest.xml file like shown below:

    <receiver android:name=”.MTractionMultipleInstallReceivers” android: exported=”true”>
    <intent-filter>
    <action android:name=”com.android.vending.INSTALL_REFERRER” />
    </intent-filter>
    </receiver>

     

    Note: Make sure that you change the receiver name to the one as you created above.

At this point in time you can validate your install tracking with our mTraction Testing Applciation. Please refer to this documentation and follow the steps as mentioned: mTraction Android SDK Testing

 –

3. App Session Tracking (Optional)

Note: App Session implementation is optional for your Application. However, for Active Sessions and Session duration related data – this needs to be configured in your Application. Also note that this can generate a lot of traffic and hence cost if the request is large.

We have provided two different solutions, Standard Solution & Alternate Solution to handle Session tracking in your Application based on the supported Android versions. Use the alternate solution if your Application supports Android versions 4.0 or below (i.e, Ice Cream Sandwich – API Level 14 or below). Choose one of the solutions below:

  • The Standard Solution is supported by most of the applications and works in a manner that lets the SDK listen to and track the various state changes that happens inside the Application (For example: App moving to foreground/background). Please follow the below steps:
    1. If you don’t have a custom Application class, create one and specify the name in your AndroidManifest.xml as follows.

      <application
      android:name=".MyApplication">

       

    2. Make the following modifications to your Application class.
      • Import the MTractionActivityLifecycleCallbacks package.
        import com.mtraction.mtractioninapptracker.MTractionActivityLifecycleCallbacks;
      • Register MTractionActivityLifecycleCallbacks.
        @Override
        
        public void onCreate()
        {
         super.onCreate();
         registerActivityLifecycleCallbacks(
                  new MTractionActivityLifecycleCallbacks(this));
        }
  • To enable/disable session tracking put below tag in android.manifest file. By default session tracking will be enabled in case below tag is missing in the android.manifest file.
    • // mTraction Session Tracking.
      <meta-data
      android:name="mt_DisableSessionTracking"
      android:value="true"/> //"true" means disable, "false" means enable, by default "false" i.e. enabled

4. In App Events (Optional)

  • At this stage, you might be interested in implementing certain In App events that needs to be tracked in order to measure your Application’s User Engagement after being installed. We have provided a list of generic events that you may need to implement depending on its necessity to your Application. Please follow the documentation (with examples) to implement them on your Application: Generic In App Events Setup
  • We have also provided sets of predefined In App events along with their respective keys setup (with example usage) based on the Industry or Vertical your Application is associated with. Please refer to the link to the various Vertical based Events integration guides: Vertical Specific Events Setup Guides
  • Additionally, you can implement custom events to track specific behavior on your application. Please follow the documentation (with example): Custom Events Setup Guide

5. CRM Integration – Android SDK

  • Enable Push Notification:
    1. Copy the MTractionPushReceiver.java file to your application main Package folder. Change the Package Name at the top of the file, to the package name of the main project. .
    2. Enable push notification feature for your application.
      <meta-data android:name=”mt_PushNotification” android:value=”true” />
       
      
    3. Permission Setting in Manifest.xml file
      <uses-permission android:name=”android.permission.GET_ACCOUNTS”/>
      <uses-permission android:name=”android.permission.WAKE_LOCK”/>
      <permission android:name=”PACKAGE_NAME.permission.C2D_MESSAGE” android:protectionLevel=”signature”/>
      <uses-permission android:name=”PACKAGE_NAME.permission.C2D_MESSAGE”/>
      <uses-permission android:name=”com.google.android.c2dm.permission.RECEIVE”/>
      <uses-permission android:name=”android.permission.VIBRATE”/>
      <uses-permission android:name=”android.permission.GET_TASKS” />Note: To set up your permissions, Replace "YOUR_PACKAGE_NAME" with your own app's package name.

      Note: To set up your permissions, Replace “YOUR_PACKAGE_NAME” with your own app’s package name.

    4. Open the AndroidManifest.xml file in your project and add the following Receiver settings.
      <receiver android:name=”com.mtraction.gcm.GCMBroadcastReceiver ”
      android:permission=”com.google.android.c2dm.permission.SEND”>
      <intent-filter>
      <action android:name=”com.google.android.c2dm.intent.RECEIVE”/>
      <action android:name=”com.google.android.c2dm.intent.REGISTRATION”/>
      <category android:name=”PACKAGE_NAME”/>
      </intent-filter>
      </receiver>Note: To set up your permissions, Replace "YOUR_PACKAGE_NAME" with your own app's package name.

      Note:To set up your permissions, Replace “YOUR_PACKAGE_NAME” with your own app’s package name. .

    5. Setting up push service
      <service android:name=”com.mtraction.mtractionpushtracker.PushService”>
      <meta-data android:name=”callback_receiver”android:value=”.MTractionPushReceiver”/>
      </service>

      Note: Implement/invoke own method to handle deep linking within the application.

    6. Configure Push Sender ID
      < meta-data android:name=”MTRACTION_SENDER_ID” android:value=”senderid:APP_PROJECT_ID”/>
      

      Note:  APP_PROJECT_ID is the project number provide by Google console Projects Setup . 

    7. Set Push Notification Timer (Optional)
      <meta-data android:name=”mt_pnt”android:value=”120″/>
    8. When user open the push notification item, SDK starts a timer (with specified timer value in mt_pnt key) and will send push_Id along with the tracked event to the server (this process is to track triggered events through push notification and it’s usage). On Above configuration example,timer value is -120 seconds which can be modified as per the application requirement, it’s default value is 3600 seconds.
       

 

  • Configure Push Notification:
    1. Push Notification Customization setting for Vibrate,Sound and Icon: By default,SDK use application icon to display notification on notification drawer with sound and vibrate enables. For User’s who wants to use their custom icon or custom sound or vibrate, We provide a configuration class called MTractionNotificationConfigurator to help. For reference check below example –

2qYCcd9PAtfcYIm79WNT8qEqQpvLVodp7Q.png

 

MTractionNotificationConfigurator notificationConfigurator = MTractionNotificationConfigurator .getInstance(this);
notificationConfigurator.config(R.drawable.ic_launcher, true, true,R.raw.soundID ,new MTractionCustomNotification() {
@Override
public void onMTractionPushReceive(Bundle pBundle) {
// TODO Auto-generated method stub
String title = pBundle.getString(“title”);
String message = pBundle.getString(“message”);
}
});

 

Note: Ideally it should be implemented in the MainActivity class after Download Tracking call..

 

2. Enable/Disable Push Notification Feature (Optional)
Add the following below code if you want to enable/disable push notification feature at any time in your application.

MTractionNotificationConfigurator.getInstance(this).setEnablePushNotification(false/true);

Articles

Was this article helpful to you? Yes No

How can we help?