Initital SDK Setup

Step 1: Getting the SDK

Maven

Attention

We use the JitPack as a Maven distribution service. As the SDK is hosted in a private GitHub repository, you have to setup your environment as shown on JitPack Private Repositories docs: https://jitpack.io/private#auth before you continue

In order to get the 360dialog SDK via Maven first add the following line to your project’s build.gradle file:

1
2
3
4
5
6
allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}

then in your application’s module build.gradle file you can use the SDK dependency:

1
2
3
4
dependencies {
    ...
    compile 'com.github.360dialog:sdk-android:3.9.2'
}

Submodule

To integrate the 360dialog SDK using a git submodule, add the 360dialog repository to your project

git submodule add git@github.com:360dialog/sdk-android.git d360sdk

Edit your project’s settings.gradle to include the SDK module:

1
2
include ':app'
include ':d360sdk/sdk'

Include the 360dialog SDK in your app’s build.gradle file

1
2
3
4
5
// (...)
dependencies {
    // (...)
    compile project(':d360sdk/sdk')
}

Step 2: Integrate the SDK

The 360dialog SDK should be initialized in the Application#onCreate() method which is executed once the app is initialized:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        String dialogApiKey = "API-KEY";
        String dialogAppId = "app";

        D360Options sdkOptions = new D360Options(dialogAppId, dialogApiKey);
        D360.init(sdkOptions, getApplicationContext());

        // Start the app visibility tracking & push notifications handling
        registerActivityLifecycleCallbacks(new D360ActivityLifecycleCallbacks());
    }
}

To make sure your Application class will be executed you have to include its name in your AndroidManifest.xml file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.threesixtydialog.application"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:name=".MyApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">

        <!-- Rest of the AndroidManifest.xml file -->

    </application>
</manifest>

Step 3: Compile and run

At this point you can already compile and run the application. The 360dialog SDK will be able to register, receive a device id and send events. In the logcat you should see an output similar to this:

I/D360: [SdkCore#init()] Starting the 360dialog SDK
(...)

I/D360:

##################################### SDK device id #################################################
   iyRPX67gMRL4jcbsBhhs4pDqArJN4s6f59EruBE8T9YTzhk5s0000000000000000000000000000000000000
#####################################################################################################

Step 4: Add push notifications

To be able to receive push notifications, please follow the steps of the Push Notifications integration.

Note

The push notification integration is required even if you don‘t plan to use push campaigns. The 360dialog SDK uses the push channel for internal purposes.

Notes

AndroidManifest.xml file

There are no additional AndroidManifest.xml entries you need to add to your file. As long as the app is compiled using the default Android Studio configuration, the Manifest Merger tool will take care of adding all the entries required by the 360dialog SDK.

In case the Manifest Merger tool is disabled, please refer to the sdk/src/main/AndroidManifest.xml file in order to get the required entries manually.

Permissions used by the 360dialog SDK

  • android.permission.INTERNET - This permission is required to perform any HTTP(S) requests.
  • android.permission.ACCESS_NETWORK_STATE - This permission is used to check if the device can access the internet or not.