Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Go to Haptik Website
  • Contact Us
  • Home
  • Deployment
  • Android SDK

Push notifications on Android SDK

Written by Soham Amburle

Updated on February 20th, 2024

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Getting Started
    Build Deploy Analyse Manage Account Bot Deactivation
  • Bot Building
    Essentials Smart Skills Steps User Messages Bot Responses Entities Connections Customisations User feedback collection Testing Whatsapp Bots NLU Bot Maintenance
  • Smart Agent Chat
    Set up Admin Settings MyChats Section (Agent Inbox) Live Traffic Section Teams Section Archives Section Analytics Plans on Smart Agent Chat
  • Conversation Design
    Design Basics Design Guides Designing for Platforms Designing WhatsApp Bots
  • Developer Guides
    Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
  • Deployment
    Web SDK WhatsApp Facebook Instagram Sunshine Conversation LINE Google Business Messages Telegram MS Teams Bot as an API iOS SDK Android SDK
  • External Agent Tool Setup
    Zendesk Chat Salesforce Service Cloud Freshchat Zoho NICE CXOne Gorgias
  • Analytics & Reporting
    Intelligent Analytics
  • Notifications
    SMS Notifications Success Measurement
  • Commerce Plus
    Catalog Integration Bot Building Guide Channel Deployments Unified ML Pipeline Documentation
  • Troubleshooting Guides
    Error Messages FAQs
  • Release Notes
+ More

Push notifications can considerably enhance your customer experience. Haptik SDK can also be configured to receive and handle Push Notifications for the conversation.

We use Firebase Cloud Messaging for push notifications. Firstly, you will have to update the GCM key in your Partner tool, which is available on the Haptik platform. You can navigate to this tool by logging in to Haptik and the admin tools > partner. 

To further enable push notification in HaptikSDK, you have to perform the following three steps :

Add Manifest Entry -

The following Activity needs to be added to your Manifest and add your desired activity as parent activity. This is required so that the user can be navigated to the proper activity when user presses the back button.

<application>
. 
. 
<activity android:name="ai.haptik.android.wrapper.sdk.HaptikWebView" 
          android:parentActivityName=".MainActivity" />
. 
.
</application>

Sync Notification Token -

You just need to pass the notification token to Haptik SDK so that the Haptik platform

can trigger push notifications from the backend whenever required.

Forward Notification to Haptik SDK -

Whenever you receive a notification check if it's from the Haptik platform. If it's a Haptik notification forward it to Haptik SDK.

Example:

Kotlin Code:

class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage : RemoteMessage) {
        val data = remoteMessage.data
        // check if it's Haptik notification
        if (HaptikSDK.isHaptikNotification(data)) {
            HaptikSDK.handleNotification(
                applicationContext,
                data,
                // Icon to show in notification
                R.mipmap.ic_launcher_round
            )
        }
    }
    override fun onNewToken(token: String) {
        super.onNewToken(token)
        HaptikSDK.setNotificationToken(applicationContext, token)
    }
}

Java Code:

public class MyFirebaseInstanceMessagingService extends FirebaseMessagingService {
   @Override
   public void onMessageReceived(@NonNull RemoteMessage message) {
       super.onMessageReceived(message);
       Map<String, String> data = message.getData();
       if(HaptikSDK.INSTANCE.isHaptikNotification(data)){
           HaptikSDK.INSTANCE.handleNotification(this, data, R.mipmap.ic_launcher);
       }
   }


   @Override
   public void onNewToken(@NonNull String token) {
       super.onNewToken(token);
       HaptikSDK.INSTANCE.setNotificationToken(getApplicationContext(), token);
   }
}

Initialise Haptik SDK

To handle the case where user taps on notification and the app was in killed state, we must initialised Haptik SDK. For this use the Application class to initialise Haptik SDK.

Code:

class App : Application(), SignupDataCallback {
    override fun onCreate() {
        super.onCreate()
        // Step 1: You must initialise Haptik SDK
        val initData = InitData()
        HaptikSDK.init(applicationContext, initData)
    }

    // Step 2(Optional): If you're using custom signup. You need to implement this method which we'll call while opening up SDK.
    // This method is defined in SignupDataCallback interface
    override fun signupData(): SignupData {
        return SignupData().apply {
            authCode = "AUTH_CODE"
            authId = "USER_AUTH_ID"
            signupType = "SIGNUP_TYPE"
        }
    }
}


Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Logging out of Android SDK

Platform

  • Conversation Studio
  • Smart Skills
  • Advanced NLU
  • Intelligent Analytics
  • Omnichannel
  • Smart Agent Chat
  • Enterprise Security
  • Integrations

Solutions

  • Conversational Commerce
  • Lead Generation
  • Customer Care
  • WhatsApp
  • Conversational IVR
  • Google Business Messages

Industries

  • Retail/ E-Commerce
  • Financial Services
  • Travel & Hospitality
  • Telecom

Knowledge

  • ROI Calculator
  • Reports & Research
  • Case Studies
  • Webinars
  • ISAT
  • Tech Blog
  • Business Blog
  • Resources
  • Haptik v/s Yellow
  • Haptik v/s Liveperson
  • Haptik v/s IBM Watson
  • Haptik v/s Verloop
  • Conversations on AI

Company

  • Why Haptik
  • About Us
  • Careers
  • News & Media
  • Awards & Recognition
  • Contact Us
  • Partnerships
  • Investor Relations

Subscribe

Sign up to recieve the latest updates

Find us on

  • Twitter-footer
  • Linkedin-footer
  • YT-footer
  • Insta-footer
  • G2-footer
  • Facebook-footer

Knowledge Base Software powered by Helpjuice

Copyright © jio Haptik Technology Limited 2021 | Data Security & Privacy Policy | GDPR

North America | Asia Pacific | Africa | enterprise@haptik.ai

Definition by Author

0
0