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

Push Notification

Render notification using Netcore SDK

Once you are done with the FCM setup, call the notification rendering method inside your FirebaseMessagingService.

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

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        boolean pushFromSmartech = Smartech.getInstance(new WeakReference<Context>(context)).handlePushNotification(remoteMessage.getData().toString());
        if (!pushFromSmartech) {
            //Handle the notification received from other sources
        }
    }
}
class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onNewToken(token: String) {
        Smartech.getInstance(WeakReference(context)).setDevicePushToken(token)
    }

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        val pushFromSmartech: Boolean = Smartech.getInstance(
            WeakReference(context)).handlePushNotification(remoteMessage.data.toString())
            if (!pushFromSmartech) {
                //Handle the notification received from other sources
            }
    }
}

Fetch Custom Payload and Deeplink on click of Notification

You can set custom key-value pairs and deeplink for your notification. In order to fetch this custom payload data and deeplink from push notification, add given snippet in the activity which is provided in deeplink.

Bundle bundle = getIntent().getExtras();
        JSONObject jsonObject = new JSONObject(bundle.getString("customPayload"));
        String deeplink = bundle.getString("deeplink");
val bundle:Bundle? = intent.extras;
        val jsonObject: JSONObject = JSONObject(bundle!!.getString("customPayload"));
        val deeplink: String? = bundle.getString("deeplink");

If you want to know how to send Custom Key Value pairs in push notification from Smartech panel - read more out it here.

Custom Push Notification Icon

With the launch of Android 5 (Lollipop), the notification icons are rendered differently in the notification bar at the top. By default, Smartech SDK uses the app’s icon for both the small icon as well as the large icon.

If you want to set a custom notification icon, add the following meta data entry in your AndroidManifest.xml.

<!--For Small icon :	-->
<meta-data  
	android:name="SMT_SMALL_NOTIFICATION_ICON"  
	android:value="<small_notification_icon_name>"/>

 <!--For Large icon (Optional): -->
<meta-data  
	android:name="SMT_LARGE_NOTIFICATION_ICON"  
	android:value="<large_notification_icon_name>"/>

📘

  1. notification_icon_name is the name of your file in the drawable directory without the file extension.
  2. The notification icon being used should strictly be in .png transparent format as per Google’s UI guidelines​.
  3. The method NetcoreSDK.setPushIcon() is deprecated from SDK v1.2.8.

Changing Push Notification Icon Color

To change the color of notification icon, add given snippet inside the onCreate() method of the Application Class​​.

Smartech.getInstance(new WeakReference<Context>(context)).setPushIconColor(<argb>);

// Sample code for reference purpose only  
Smartech.getInstance(new WeakReference<Context>(context)).setPushIconColor(Color.RED);

// If you are applying color from resource file.
Smartech.getInstance(new WeakReference<Context>(context)).setPushIconColor(ContextCompat.getColor(context, R.color.colorName));
Smartech.getInstance(WeakReference(context)).setPushIconColor(<argb>)

// Sample code for reference purpose only
Smartech.getInstance(WeakReference(context)).setPushIconColor(Color.RED)

// If you are applying color from resource file.
Smartech.getInstance(WeakReference(context)).setPushIconColor(ContextCompat.getColor(context, R.color.colorName))

Get the Push Icon

To retrieve push icon set to Smartech use getPushIconColor() method.

int color=Smartech.getInstance(new WeakReference<Context>(context)).getPushIconColor();
val color:Int= Smartech.getInstance(WeakReference(context)).getPushIconColor()

Reset Push Notification Icon Color

To reset the color of notification icon, add the given snippet.

Smartech.getInstance(new WeakReference<Context>(context)).resetPushIconColor();
Smartech.getInstance(WeakReference(context)).resetPushIconColor()