Android SDK
To integrate your Android project with Netcore CE Android SDK, follow these steps
Android Project Prerequisites:
- Minimum SDK target API level 21 or later
- Use Gradle 4.1 or later
Step 1: Integrate the latest Netcore CE SDK
- Make the following changes in the app-levelbuild.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 {
}
maven { url = uri("https://artifacts.netcore.co.in/artifactory/android") }
Note
WorkManager Version 2.7.0 is required for apps targeting Android 12 (S).
Perform Gradle Sync to build your project and incorporate the dependency additions noted above.
Step 2: Initialize Smartech SDK
- 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 the steps given here for the new method and refer here for the old method. 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.
- Add the below-mentioned code in the
onCreate()method of your Application class to initialize the Smartech SDK.
import com.netcore.android.Smartech;
import com.netcore.android.SMTDebugLevel;
import java.lang.ref.WeakReference;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// 1. Initialize Smartech SDK
Smartech.getInstance(new WeakReference<>(getApplicationContext()))
.initializeSdk(this);
// 2. Enable verbose debug logs
Smartech.getInstance(new WeakReference<>(getApplicationContext()))
.setDebugLevel(SMTDebugLevel.Level.VERBOSE);
// 3. Track app install and update events
Smartech.getInstance(new WeakReference<>(getApplicationContext()))
.trackAppInstallUpdateBySmartech();
}
}
import com.netcore.android.Smartech
import com.netcore.android.SMTDebugLevel
import java.lang.ref.WeakReference
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// 1. Initialize Smartech SDK
Smartech.getInstance(WeakReference(applicationContext))
.initializeSdk(this)
// 2. Enable verbose debug logs
Smartech.getInstance(WeakReference(applicationContext))
.setDebugLevel(SMTDebugLevel.Level.VERBOSE)
// 3. Track app install and update events
Smartech.getInstance(WeakReference(applicationContext))
.trackAppInstallUpdateBySmartech()
}
}
- Make sure you have registered your Application class in the Application tag inside the
manifest.xmlfile.
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.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.netcore.android.smartech.base.sdk.SMTBundleKeys;
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());
}
}
}
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.netcore.android.smartech.base.sdk.SMTBundleKeys
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:
