Skip to main content

How to use Diyalog Android SDK

Diyalog SDK is used for enabling messaging for your application. It is a multi-platform communication Messaging SDK for mobile and web. It is easy to integrate, save development cost and delight users with a stable, secure and customization messaging.

SDK Supports#

Diyalog SDK supported with Android 4.0.3(API level 15) & Above

Integration Steps#

Step 1: Open your Project level build.gradle file and add below mentioned maven repository Url in build.gradle file.

repositories {
jcenter()
mavenCentral()
...
maven {
credentials {
username mavenUser
password mavenPassword
}
url 'https://mavenrepo.diyalog.im/repository/maven-releases/'
}
}

Note: You will need credential for access our private repository. We will create a user for your company. Please contact us to get mavenUser and mavenPassword for accessing repository.

Step 2: Open module level build.gradle file.

  • a. Set compile and target sdk version to 26 and above

    compileSdkVersion 26
    defaultConfig {
    --
    minSdkVersion 15
    targetSdkVersion 26
    --
    multiDexEnabled true
    }
    dexOptions {
    javaMaxHeapSize "2g"
    }
    lintOptions {
    abortOnError false
    }
  • b. Add Diyalog Android dependency to your dependency section of module build.gradle file.

    implementation "im.diyalog:DiyalogEngine:version-no"

    if you are using 3.* version of com.squareup.okhttp3 in your project. This cause an library conflict. Because DiyalogSDk is using 4.7.2 version of com.squareup.okhttp3. For solving this, you should add DiyalogEngine dependency as follows.

    implementation ('im.diyalog:DiyalogEngine:version-no’){
    transitive true
    exclude group: "com.squareup.okhttp3"
    }

    Diyalog SDK also has feature push notification and sending location between peers. After 2020, Google Services not support apis of them for Huawei devices. we separated map and notification integration regarding as stores due to this. Therefore, you should add following Diyalog dependency based on Google and Huawei application store.

    For application that deployed to Google App Store :

    implementation "im.diyalog:DiyalogGoogleExtension:version-no"

    For application that deployed to Huawei App Gallery :

    implementation "im.diyalog:DiyalogHuaweiExtension:version-no"

    *version-no should be the current stable version of Diyalog Android SDK.

Step 3: If you will use sending and receiving location messages, you should do this step. Otherwise you can skip this step.

  • For Google Android Store :
    Open your project AndroidManifest.xml file and add below line of code inside application tag.

    <meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="YOUR_API_KEY_HERE" />

    Note : Replace YOUR_API_KEY_HERE with your actual Map API key which you will get from your google Api console To get Map API key please check Maps SDK for Android document.

  • For Huawei devices that use Huawei App Gallery :
    Add agconnect-services.json file that created with map api key with ypu app account in Huawei Mobile Services to your project.

Step 4: After all dependencies added to your project, you should initialise Diyalog. For doing this you have two choices.

  • By calling initiliasation codes
    You should call configuration setting methods and initialise methods of Diyalog SDK in your Application class or another class that you want to start DiyalogSDK. If you want to start Diyalog your other class instead fo Application class, you must be care that calling these initialisation methods only once in your system. Therefore, we are recomending that initiliase Diyalog in your Application class.
public class Application extends android.app.Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
@Override
public void onCreate() {
super.onCreate();
//Your app code
...
// Create and initialise Diyalog
//Set required configuration
DiyalogEngine.diyalogInstance().setAppName("DemoApp");
DiyalogEngine.diyalogInstance().setApiAppId(<YOUR_APP_ID>);
DiyalogEngine.diyalogInstance().setApiAppKey("<YOUR_APP_KEY>");
DiyalogEngine.diyalogInstance().setEndpoints(new String[]{"wss://<YOUR_DIYALOG_SERVER_ENDPOINT_ADDRESS>"});
String[] trustedKeys = new String[]{
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_1",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_2",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_3",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_4",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_5",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_6"
};
DiyalogEngine.diyalogInstance().setTrustedKeys(trustedKeys);
// Create Diyalog
AndroidContext.setContext(getApplicationContext());
DiyalogEngine.diyalogInstance().createDiyalog(this);
DiyalogEngine.diyalogInstance().waitForReady();
// set here you application theme color
DiyalogStyle style = DiyalogEngine.diyalogInstance().style;
style.setMainColor(Color.parseColor("#FFFF4081"));
}
}
  • By extending Diyalog SDK DiyalogEngineApplication class.
    Create Application class and extend it with DiyalogEngineApplication. And override onConfigureDiyalogEngine() method. Inside that method set below configure. There is no need calling any createDiyalog function if extend DiyalogEngineApplication class of SDK. Constructor of this class will handle setting configuration and creating Diyalog.
public class DiyalogApplication extends DiyalogEngineApplication {
@Override
public void onConfigureDiyalogEngine() {
DiyalogEngine.diyalogInstance().setAppName("DemoApp");
DiyalogEngine.diyalogInstance().setApiAppId(<YOUR_APP_ID>);
DiyalogEngine.diyalogInstance().setApiAppKey("<YOUR_APP_KEY>");
DiyalogEngine.diyalogInstance().setEndpoints(new String[]{"wss://<YOUR_DIYALOG_SERVER_ENDPOINT_ADDRESS>"});
String[] trustedKeys = new String[]{
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_1",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_2",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_3",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_4",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_5",
"<YOUR_DIYALOG_ENVIRONMENT_PUBLIC_KEY_6"
};
DiyalogEngine.diyalogInstance().setTrustedKeys(trustedKeys);
// set here you application theme color
DiyalogStyle style = DiyalogEngine.diyalogInstance().style;
style.setMainColor(Color.parseColor("#FFFF4081"));
}
}

Now you are ready to use Diyalog SDK in your application. You should read the next section about configuration parameters. Diyalog SDK gives you many customization in the chat views. You can learn details about styling Diyalog in styling document.