These docs are for v1.0. Click to read the latest docs for v2.0.

Getting Started

Integrate the Smartech SDK

a. Adding Dependencies

To install the latest Smartech SDK in your project, add the following line to the dependencies section in the app-level build.gradle

implementation 'in.netcore.smartechfcm:smartech-fcm:2.5.8'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'androidx.work:work-runtime:2.3.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'in.netcore.smartechfcm:smartech-fcm:2.5.5'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'androidx.work:work-runtime-ktx:2.3.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

📘

NOTE :

  1. cancelAllWork () Cancels all unfinished work. Use this method with extreme caution! By invoking it, you will potentially affect the Smartech SDK and other modules or libraries in your codebase. It is strongly recommended that you use one of the other cancellation methods at your disposal.

  2. AndroidX is a major improvement to the original Android Support Library, which is no longer maintained. AndroidX packages fully replace the Support Library by providing feature parity and new libraries.

Android Support Revision 28.0.0 will be the last feature release under the android.support packaging, and developers are encouraged to migrate to AndroidX as all new feature development will be in the AndroidX namespace. Same would be the case of work manager version 2.0 and above. We recommend that you migrate to the AndroidX library soon and upgrade the AndroidX compatible Smartech SDK.

b. Perform gradle sync

Be sure to perform a Gradle Sync to build your project and incorporate the dependency additions noted above.

Initialize Smartech SDK

First, you need to put your Smartech panel app Id in the meta-data tag of your application's manifest file.

<meta-data
   android:name="SMT_APP_ID"
   android:value="YOUR_SMARTECH_APP_ID_HERE" />

In the onCreate() method of your Application Class includes the code below. This code will initialize the Smartech SDK.

import android.app.Application;
import in.netcore.smartechfcm.Smartech;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Smartech.getInstance(new WeakReference<>(getApplicationContext())).initializeSdk(this);
    }
}
import android.app.Application
import `in`.netcore.smartechfcm.Smartech

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate();
        Smartech.getInstance(WeakReference(applicationContext)).initializeSdk(this);
    }
}

Make sure you have registered your Application class in Application tag inside manifest.xml file.

Set Debug Level

The Level class defines a set of standard logging levels that can be used to control logging output. Using the verbose you can see the all netcore logs in logcat. You can call this method above the Necore initialization.

Smartech.getInstance(new WeakReference<>(getApplicationContext())).setDebugLevel(context, NCLogger.Level.LOG_LEVEL_VERBOSE);

Send token to Smartech SDK

If you are newly integrated with FCM -

The setDevicePushToken() method is required to send a token to SDK for sending the push notifications.

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onNewToken(String token) {
        Smartech.getInstance(new WeakReference<>(context)).setDevicePushToken(token);
    }
   }
class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onNewToken(token: String) {
        Smartech.getInstance(WeakReference(context)).setDevicePushToken(token);
    }
   }

If you are already integrated with FCM -

If you have already integrated the Firebase Cloud Messaging client app on Android, then you need to pass the generated token to Smartech SDK. You can pass the saved token to SDK by calling setDevicePushToken() method above initializeSdk()` method.

Please make sure that you are calling this method only once, i.e. on first app launch.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
       Smartech.getInstance(new WeakReference<>(getApplicationContext())).initializeSdk(this);
        if(firstrun) {
        	Smartech.getInstance(new WeakReference<>(context)).setDevicePushToken(token);
        }
		}
}
class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
          Smartech.getInstance(WeakReference(applicationContext)).initializeSdk(this)
        if (firstrun) {
         Smartech.getInstance(WeakReference(context)).setDevicePushToken(token)
        }
    }
}

If you haven't saved the token inside your app, you can re-generate it by using the following method. For more details, you can refer to the Google’s Documentation

FirebaseInstanceId.getInstance().getInstanceId()
        .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
            @Override
            public void onComplete(@NonNull Task<InstanceIdResult> task) {
                if (!task.isSuccessful()) {
                    Log.w(TAG, "getInstanceId failed", task.getException());
                    return;
                }

                // Get new Instance ID token
                String token = task.getResult().getToken();
    
                // Log and toast
                String msg = getString(R.string.msg_token_fmt, token);
                Log.d(TAG, msg);
                Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        });
FirebaseInstanceId.getInstance().instanceId
        .addOnCompleteListener(OnCompleteListener { task ->
            if (!task.isSuccessful) {
                Log.w(TAG, "getInstanceId failed", task.exception)
                return@OnCompleteListener
            }

            // Get new Instance ID token
            val token = task.result?.token

            // Log and toast
            val msg = getString(R.string.msg_token_fmt, token)
            Log.d(TAG, msg)
            Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
        })

Get the Push Token

If you want to retrieve the push token set to Smartech use the following snippet.

String fcmToken=Smartech.getInstance(new WeakReference<>(context)).getDevicePushToken();
val fcmToken:String=Smartech.getInstance(WeakReference(context)).getDevicePushToken();

Tracking the Re-Installs

Step1: Creating the full backup content file.

Create an XML file in the xml directory of your resources (i.e. res/xml/my_backup_file). Copy the below snippet in the XML file.

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="sharedpref" path="smt_guid_preferences.xml"/>
    <include domain="sharedpref" path="smt_preferences_guid.xml"/>
</full-backup-content>

Step2: Update the application to allow backup.

Add allowBackup and fullBackupContent tags in the application tag of your AndroidManifest.xml.

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:fullBackupContent="@xml/my_backup_file"
        ...
        />

📘

NOTE:

  1. Re-Installs works for users with Android OS version 6.0 and higher.
  2. The user must be logged in to his Google account and must have enabled backup and restore in order to track re-install. (and have at least 25MB space available in Google drive)

Handling Custom In-App HTML

You must implement the InAppCustomtion HTMLListener and call smartech.setInAppCustomHTMLListener() method in your application class if you are using custom HTML in-app messages.

public class MyApplication extends Application implements InAppCustomHTMLListener {
    @Override
    public void onCreate() {
        super.onCreate();
      	Smartech smartech = Smartech.getInstance(new WeakReference<>(this));
        smartech.initializeSdk(this);
        smartech.setInAppCustomHTMLListener(this);
        ....
    }

    @Override
    public void customHTMLCallback(Map<String, Object> jsonToMap) {
        // Handle In-App HTML callback.
    }
}
class SampleApplication : Application(), InAppCustomHTMLListener {
    override fun onCreate() {
        super.onCreate()
        val smartech: Smartech = Smartech.getInstance(WeakReference(this))
        smartech.initializeSdk(this)
        smartech.setInAppCustomHTMLListener(this)
        ...
    }

    override fun customHTMLCallback(payload: HashMap<String, Any>?) {
        // Handle custom HTML callback.
    }
}

Add Required Permissions to Android Manifest

You need to add the following permissions to your AndroidManifest.xml to callback the APIs.

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

Ready to run

Now you can run the application, and check the Register event getting called.

👍

Did you know?

  • Register event will send user’s FCM token to Smartech. Please ensure that token is getting generated in Register event.
  • Register event will get called on every app launch.
  • This token will be used to send push notifications from Smartech Panel.