Class WhatsAppOtpHandler

java.lang.Object
com.whatsapp.otp.android.sdk.WhatsAppOtpHandler

public class WhatsAppOtpHandler extends Object
Class responsible for handling intents sent to WhatsApp
  • Constructor Details

    • WhatsAppOtpHandler

      public WhatsAppOtpHandler()
      Default constructor
    • WhatsAppOtpHandler

      public WhatsAppOtpHandler(boolean sendSdkVersion)
      Constructor which lets developer define if sdk version should be sent in the request.
      Parameters:
      sendSdkVersion - if the sdk version should be sent
    • WhatsAppOtpHandler

      public WhatsAppOtpHandler(WhatsAppOtpIntentBuilder whatsAppOtpIntentBuilder)
      Constructor. Use this constructor if you want to provide your WhatsAppOtpIntentBuilder implementation
      Parameters:
      whatsAppOtpIntentBuilder - builder responsible for creating Intent to WhatsApp.
  • Method Details

    • sendOtpIntentToWhatsApp

      public void sendOtpIntentToWhatsApp(@NonNull android.content.Context context)

      Send and otp intent to both WhatsApp consumer and business app. This is the handshake step for WhatsApp authentication messages.

      Basically an intent to WhatsApp is created with a pending intent. This pending intent is used by WhatsApp merely to validate the creator package name against the package name defined in the Authentication message template.

      This intent is sent to WhatsApp using the "com.whatsapp.otp.OTP_REQUESTED" action

      After receiving this handshake, WhatsApp will enable the autofill feature based on the message template configuration

      Parameters:
      context - application context to broadcast the intent to WhatsApp.
    • sendOtpIntentToWhatsApp

      public android.content.Intent sendOtpIntentToWhatsApp(@NonNull android.content.Context context, @NonNull WhatsAppClientType type)

      Send and otp intent to WhatsApp. This is the handshake step for WhatsApp authentication message. Basically a intent to WhatsApp is created with a pending intent. This pending intent is used by WhatsApp merely to validate the creator package name against the package name defined in the Authentication message template.

      This intent is sent to WhatsApp using the "com.whatsapp.otp.OTP_REQUESTED" action

      After receiving this handshake, WhatsApp will enable the autofill feature based on the message template configuration

      You can choose to send to WhatsApp consumer or business, thought is recommended to send to both using sendOtpIntentToWhatsApp method

      Parameters:
      context - application context to broadcast the intent to WhatsApp.
      type - You can define wither consumer or business application.
      Returns:
    • isWhatsAppOtpHandshakeSupported

      public boolean isWhatsAppOtpHandshakeSupported(@NonNull android.content.Context context)
      Checks if either WhatsApp consumer or business has support for the otp handshake if installed.

      The handshake support is provided by the presence of a receiver on WhatsApp with the following action: "com.whatsapp.otp.OTP_REQUESTED"

      If WhatsApp is not installed, this function will return false.

      Parameters:
      context - application context
      Returns:
      true if the receiver is available on either WhatsApp consumer or business, false otherwise
    • isWhatsAppOtpHandshakeSupported

      public boolean isWhatsAppOtpHandshakeSupported(@NonNull android.content.Context context, @NonNull WhatsAppClientType type)
      Checks if WhatsApp has support for the otp handshake.

      The handshake support is provided by the presence of a receiver on WhatsApp with the following action: "com.whatsapp.otp.OTP_REQUESTED"

      If WhatsApp is not installed, this function will return false.

      You need to have the following definition in your AndroidManifest for this function to work:

           <queries>
               <package android:name="com.whatsapp"/>
               <package android:name="com.whatsapp.w4b"/>
           </queries>
       
      Parameters:
      context - application context
      type - WhatsApp client to be checked, can be either consumer or business
      Returns:
      true if the receiver is available on either WhatsApp consumer or business, false otherwise
    • isWhatsAppInstalled

      public boolean isWhatsAppInstalled(@NonNull android.content.Context context)
      Check if either WhatsApp consumer or business app is installed on the device

      You need to have the following definition in your AndroidManifest for this function to work properly:

           <queries>
               <package android:name="com.whatsapp"/>
               <package android:name="com.whatsapp.w4b"/>
           </queries>
       
      Parameters:
      context - application context
      Returns:
      true if WhatsApp is installed or false otherwise
    • isWhatsAppInstalled

      public boolean isWhatsAppInstalled(@NonNull android.content.Context context, @NonNull WhatsAppClientType type)
      Check if WhatsApp is installed on the device.

      You need to have the following definition in your AndroidManifest for this function to work properly:

           <queries>
               <package android:name="com.whatsapp"/>
               <package android:name="com.whatsapp.w4b"/>
           </queries>
       
      Parameters:
      context - application context
      type - WhatsApp type, can be either consumer or business
      Returns:
      true if WhatsApp is installed or false otherwise