Android SDK

👍

UPDATE!

We have updated our release process for SDK 2, 3 & Product Experience starting 12th April 2021! Please follow the new guidelines as mentioned below.

To integrate your Android project with Smartech Android SDK, follow these steps

📘

Android Project Prerequisites:

  • Target API level 19 or later
  • Use Gradle 4.1 or later

Step 1: Integrate the latest Smartech SDK

  1. Make the following changes in the app-level build.gradle
apply plugin: 'com.android.application'

android {
    ...
    defaultConfig { ... }
    buildTypes {
        ...
    }
}

repositories {
    maven { url 'https://artifacts.netcore.co.in/artifactory/android' }
}

dependencies {
implementation 'com.netcore.android:smartech-sdk:<<base_sdk_android_version>>'
// WorkManager Version 2.7.0 is required for apps targeting Android 12 (S), uncomment the below line based on the app side requirement

// (Java only enable below)
 // implementation 'androidx.work:work-runtime:2.7.0'

// Kotlin + coroutines enable below
 // implementation 'androidx.work:work-runtime-ktx:2.7.0'
}

buildscript {
}

📘

Note

  1. WorkManager Version 2.7.0 is required for apps targeting Android 12 (S).

  2. Perform Gradle Sync to build your project and incorporate the dependency additions noted above.

Step 2: Initialize Smartech SDK

  1. Put your Smartech panel's app Id in the meta-data tag of your application's manifest file, it should be added within the application tag, but outside of any component within the application tag.
    To get Smartech App ID, follow steps given here , else please get in touch with your account manager to get the value of SMT_APP_ID
<meta-data
   android:name="SMT_APP_ID"
   android:value="YOUR_SMARTECH_APP_ID_HERE" />

🚧

Note

Please make sure you enter your own Smartech App ID in the code snippet before putting it in the meta-data tag of your application's manifest file.

  1. Add the below mentioned code in the onCreate() method of your Application class to initialize the Smartech SDK.
@Override
public void onCreate() {
	super.onCreate();
	Smartech.getInstance(new WeakReference<>(context)).initializeSdk(this);
}
override fun onCreate() {
	super.onCreate()
	Smartech.getInstance(WeakReference(applicationContext)).initializeSdk(this)
}
  1. Make sure you have registered your Application class in the Application tag inside the manifest.xml file.

Step 3: Setting up Proguard rules

Add the following lines in proguard-rules.pro to retain Smartech SDK files during the proguard process.

# Smartech Base SDK
-dontwarn com.netcore.android.**
-keep class com.netcore.android.**{*;}
-keep class * implements com.netcore.android.**.* {*;}
-keep class * extends com.netcore.android.**.* {*;}

Step 4: Deeplink handling

Implement a BroadcastReceiver for the Deeplinks.

public class DeeplinkReceiver extends BroadcastReceiver {
   @Override
   public void onReceive(Context context, Intent intent) {
       try {
           Bundle bundleExtra = intent.getExtras();
           if (bundleExtra != null) {
               String deepLinkSource = bundleExtra.getString(SMTBundleKeys.SMT_KEY_DEEPLINK_SOURCE);
               String deepLink = bundleExtra.getString(SMTBundleKeys.SMT_KEY_DEEPLINK);
               String customPayload = bundleExtra.getString(SMTBundleKeys.SMT_KEY_CUSTOM_PAYLOAD);
               if (deepLink != null && !deepLink.isEmpty()) {
                   // handle deepLink for redirection. Here you can use deepLinkSource for redirection if required
               }
               if (customPayload != null && !customPayload.isEmpty()) {
                   // handle your custom payload based on deeplink source like below if required
               }
           }
       } catch (Throwable t) {
           Log.e("DeeplinkReceiver", "Error occurred in deeplink:" + t.getLocalizedMessage());
       }
   }
}

class DeeplinkReceiver : BroadcastReceiver() {
   override fun onReceive(context: Context?, intent: Intent?) {
       try {
           val bundleExtra = intent?.extras
           bundleExtra?.let {
               val deepLinkSource = it.getString(SMTBundleKeys.SMT_KEY_DEEPLINK_SOURCE)
               val deepLink = it.getString(SMTBundleKeys.SMT_KEY_DEEPLINK)
               val customPayload = it.getString(SMTBundleKeys.SMT_KEY_CUSTOM_PAYLOAD)
               if (deepLink != null && deepLink.isNotEmpty()) {
                   // handle deepLink for redirection. Here you can use deepLinkSource for redirection if required
               }
               if (customPayload != null && customPayload.isNotEmpty()) {
                   // handle your custom payload based on deeplink source like below if required
               }
           }
       } catch (t: Throwable) {
           Log.e("DeeplinkReceiver", "Error occurred in deeplink:${t.localizedMessage}")
       }
   }
}

Register the BroadcastReceiver inside the Application class.

When targetSdkVersion >= 34 (Android 14 and above)

DeeplinkReceiver deeplinkReceiver = new DeeplinkReceiver();
IntentFilter filter = new IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
   context.registerReceiver(deeplinkReceiver, filter, Context.RECEIVER_EXPORTED);
} else {
   context.registerReceiver(deeplinkReceiver, filter);
}

val deeplinkReceiver = DeeplinkReceiver()
val filter = IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
   context.registerReceiver(deeplinkReceiver, filter, RECEIVER_EXPORTED)
} else {
   context.registerReceiver(deeplinkReceiver, filter)
}

When targetSdkVersion <= 33 (Android 13 and below)

DeeplinkReceiver deeplinkReceiver = new DeeplinkReceiver();
        IntentFilter filter = new IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK");
        context.registerReceiver(deeplinkReceiver, filter);
val deeplinkReceiver = DeeplinkReceiver()
        val filter = IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK")
        context.registerReceiver(deeplinkReceiver, filter)

Step 5: Choose Features

Now that the basic setup is completed, you can choose to move to either of below features:

  1. Customer Engagement Channels like Push Notifications & In-app Messages
  2. User & Event Tracking
  3. Product Experience