Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
4. Open your strings.xml file. Example path: /app/src/main/res/values/strings.xml and add a new string with the name "partnerKey" and value as your "appKey"
5. Open your AndroidManifest.xml and add a meta-data element to the application element
Copy
In order to clear the resources taken up by SDK, you can use the method TruecallerSDK.clear();
You can call this method when the activity/fragment in which you have initialised the SDK is getting killed/destroyed.
For example :
Copy
7. Add the following condition in the onActivityResult method TruecallerSDK.getInstance().onActivityResultObtained( this,requestCode, resultCode, data)
Copy
Note : In case you passed Fragment in the getUserProfile() method [ point #6 ], override the onActivityResult() method in your corresponding Fragment
8. In your selected Activity/Fragment, either make the component implement ITrueCallback or create an instance of it :
Copy
onSuccessProfileShared() method will be called in either of the following two scenarios : a.) When the user has agreed to share his profile information with your app by clicking on the "Continue" button on the Truecaller dialog b.) When a non Truecaller user is already verified previously on the same device. This would only happen when the TruecallerSdkScope#SDK_OPTION_WITH_OTP
is selected while initialising the SDK to provision for the verification of non-Truecaller users also.
onFailureProfileShared() method will be called when some error occurs or if an invalid request for verification is made. You'll get the respective error code as per the details mentioned here.
onVerificationRequired() method will only be called whenTruecallerSdkScope#SDK_OPTION_WITH_OTP
is selected. This will be called when the user is not a Truecaller app user. Also, you'll get a Nullable TrueError only when TC app is installed and user is logged in. For other cases, it would be null. This optional TrueError can be used to determine the user action that led to initiating manual verification. So using this TrueError, you can get to whether the user pressed on the footer CTA on the verification screen OR the system back button.
Write all the relevant logic in the above callback methods to handle the scenarios appropriately.
Handling error responses for cases of verifying non-Truecaller users
Error Code | Error Message | Description |
---|
Truecaller SDK provides you with capabilities to configure the following :
If you are already using Truecaller SDK with pop-up variant of the verification screen, you can upgrade to the bottom sheet layout by simply making changes to the configuration options in your TruecallerSdkScope object. Refer to the below section for details on all the customisation capabilities and the possible values you may set.
Contextual text prefix [ .loginTextPrefix() ] To provide appropriate context of verification to the Truecaller user, use one of the below mentioned TruecallerSdkScope values to show the corresponding message to the user.
Contextual text suffix [ .loginTextSuffix() ] To provide appropriate context of verification to the Truecaller user and set the suffix string
Button text options [ .ctaTextPrefix() ] To set the prefix on the CTA button
Button shape [ .buttonShapeOptions() ] To chose the shape of the CTA button
Footer CTA text [ .footerType() ] To configure the text of the additional footer CTA present at the bottom
Privacy policy text [ .privacyPolicyUrl() ] To add your privacy policy link on the verification screen ( optional ), you can configure the respective hyperlink as mentioned below
Copy
Terms of service text [ .termsOfServiceUrl() ] To add your terms of service link on the verification screen ( optional ), you can configure the respective hyperlink as mentioned below
Copy
Language To customise the profile dialog in any of the supported Indian languages To do so, add the following lines before calling the "getUserProfile()" method as mentioned in the previous step
Copy
Currently supported languages :
NOTE : In case the input locale is not supported, the profile will by default be shown in English language.
Using the SDK with your Android Studio Project
Truecaller SDK does not require any additional app permissions if you are using the SDK for verification of only Truecaller users.
To enable verification flow for non-Truecaller users as well, the SDK needs specific android permissions to enable the drop call based background verification flow. For details, please refer
If you haven't already completed for your app, we recommend you to complete that first before proceeding with the integration and also refer to the .
Text to use | TruecallerSdkScope value |
To get started | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_GET_STARTED |
To continue | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_CONTINUE |
To place order | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_PLACE_ORDER |
To complete your order | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_COMPLETE_YOUR_PURCHASE |
To checkout | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_CHECKOUT |
To complete your booking | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_COMPLETE_YOUR_BOOKING |
To proceed with your booking | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_PROCEED_WITH_YOUR_BOOKING |
To continue with your booking | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_CONTINUE_WITH_YOUR_BOOKING |
To get details | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_GET_DETAILS |
To view more | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_VIEW_MORE |
To continue reading | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_CONTINUE_READING |
To proceed | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_PROCEED |
For new updates | TruecallerSdkScope.LOGIN_TEXT_PREFIX_FOR_NEW_UPDATES |
To get updates | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_GET_UPDATES |
To subscribe | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_SUBSCRIBE |
To subscribe and get updates | TruecallerSdkScope.LOGIN_TEXT_PREFIX_TO_SUBSCRIBE_AND_GET_UPDATES |
Suffix string | TruecallerSdkScope value |
please login | TruecallerSdkScope.LOGIN_TEXT_SUFFIX_PLEASE_LOGIN |
please signup | TruecallerSdkScope.LOGIN_TEXT_SUFFIX_PLEASE_SIGNUP |
please login/ signup | TruecallerSdkScope.LOGIN_TEXT_SUFFIX_PLEASE_LOGIN_SIGNUP |
please register | TruecallerSdkScope.LOGIN_TEXT_SUFFIX_PLEASE_REGISTER |
please sign in | TruecallerSdkScope.LOGIN_TEXT_SUFFIX_PLEASE_SIGN_IN |
please verify mobile number | TruecallerSdkScope.LOGIN_TEXT_SUFFIX_PLEASE_VERIFY_MOBILE_NO |
Button text to use | TruecallerSdkScope value |
Use | TruecallerSdkScope.CTA_TEXT_PREFIX_USE |
Continue with | TruecallerSdkScope.CTA_TEXT_PREFIX_CONTINUE_WITH |
Proceed with | TruecallerSdkScope.CTA_TEXT_PREFIX_PROCEED_WITH |
Button shape | TruecallerSdkScope value |
Round | TruecallerSdkScope.BUTTON_SHAPE_ROUNDED |
Rectangle | TruecallerSdkScope.BUTTON_SHAPE_RECTANGLE |
Footer CTA string | TruecallerSdkScope value |
Use another number | TruecallerSdkScope.FOOTER_TYPE_CONTINUE |
Use another method | TruecallerSdkScope.FOOTER_TYPE_ANOTHER_METHOD |
Enter details manually | TruecallerSdkScope.FOOTER_TYPE_MANUALLY |
Later | TruecallerSdkScope.FOOTER_TYPE_LATER |
Language | locale value to use |
english | en |
hindi | hi |
marathi | mr |
telugu | te |
malayalam | ml |
urdu | ur |
punjabi | pa |
tamil | ta |
bengali | bn |
kannada | kn |
swahili | sw |
arabic | ar |
Once you receive a callback in your VerificationCallback
instance with the requestCode TYPE_MISSED_CALL_RECEIVED
or TYPE_OTP_RECEIVED , you can complete the verification process by calling the following method from within your activity :
Copy
You need to create a TrueProfile instance by passing the user's first and last name as defined above.
Please note that the first name and last name values to be passed in the above method call need to follow below mentioned rules :
The strings need to contains at least 1 alphabet, and cannot be completely comprised of numbers or special characters
String length should be less than 128 characters
First name is a mandatory field, last name can be empty ( but non nullable )
Depending on whether the verification medium is drop call or OTP, you need to call one of the following methods respectively:
DropcallOTPCopy
You need to call this method once you have received callback with requestCode as TYPE_MISSED_CALL_RECEIVED
in your VerificationCallback
instance
After you call the above method, you will receive a callback in your VerificationCallback
instance with requestCode as TYPE_VERIFICATION_COMPLETE,
which completes your verification process.
Whenever you get the verification callback with requestType as TYPE_VERIFICATION_COMPLETE,
you would get an accessToken as a parameter in the verificationDataBundle. You can use this access token to validate the authenticity of the verification flow by making an API call from your server to Truecaller's server. For details on this part, please refer here.
This section defines the steps that can be used to trigger verification of non Truecaller app users which will be powered via Truecaller's drop call based verification flow
In order to verify non Truecaller users, the SDK requires the below mentioned permissions -
Copy
Once you receive a callback in the ITrueCallback#onVerificationRequired(),
you can initiate the verification for the user by calling the following method:
Copy
Here -
the first parameter is the country code of the mobile number for which the verification needs to be triggered
the second parameter (PHONE_NUMBER_STRING) is the mobile number to be verified. Please ensure proper validations are in place so as to send correct phone number string to the above method, otherwise an exception would be thrown
the third parameter is an instance of VerificationCallback
as defined here
the fourth parameter is an instance of FragmentActivity
Please note that Truecaller SDK v2.8.0 currently supports the verification for non-Truecaller users for Indian numbers only.
Once you initiate the verification via TruecallerSDK.getInstance().requestVerification()
method, you will receive either a callback in your VerificationCallback
instance with a specificrequestType
as described below
Copy
onRequestSuccess() method is called under any of the following scenarios -
When drop call is successfully initiated for the input mobile number. In this case, you will get the requestCode as VerificationCallback.TYPE_MISSED_CALL_INITIATED
When drop call is successfully detected on that device by the SDK present in your app. In this case, you will get the requestCode as VerificationCallback.TYPE_MISSED_CALL_RECEIVED
When the verification is successful for a particular number. In this case, you will get the requestCode as VerificationCallback.TYPE_VERIFICATION_COMPLETE
When the user is already verified on that particular device before. In this case, you will get the requestCode as VerificationCallback.TYPE_PROFILE_VERIFIED_BEFORE
When requestCode is VerificationCallback.TYPE_MISSED_CALL_INITIATED
, you will receive an additional parameter for the time to live i.e TTL (in seconds) which is passed as String extra in the VerificationDataBundle
of onRequestSuccess()
. This value determines amount of time left to complete the verification. You can use this value to show a waiting message to your user before they can try for another attempt. Once the TTL expires, you can either auto-retry the verification by calling the requestVerification() method automatically with the same input parameters OR you can also take the user back to the number input screen to enter a different number for verification.
NOTE: Truecaller SDK v2.5.0 & above won't throw timeout exceptions for missed call, so please use the TTL as stated above to control the time out scenario.
When the requestCode is VerificationCallback.TYPE_ALREADY_VERIFIED_BEFORE or VerificationCallback.TYPE_VERIFICATION_COMPLETE, it means that the user verification via Truecaller SDK is complete. In these cases, the SDK will share an additional access token with your application, which you may then use to validate the response at your server end. To fetch the access token, you may use the following code snippet :
//For when the control goes to TYPE_ALREADY_VERIFIED_BEFORE extras.getProfile().accessToken
//For when the control goes to TYPE_VERIFICATION_COMPLETE extras.getString(VerificationDataBundle.KEY_ACCESS_TOKEN)
Post fetching the access token, you may perform the server side validation by referring to the steps mentioned in the later part of the documentation here.
onRequestFailure() method will be called when some error has occurred while verifying the provided mobile number. You will receive the appropriate error message from TrueException using TrueException#getExceptionMessage().
For details of different possible error types you may encounter, please refer to the next section.
Advanced steps for validating the request-response correlation:
Every request sent via a Truecaller app that supports Truecaller SDK has a unique identifier. This identifier is bundled into the response for assuring a correlation between a request and a response. If you want you can check this correlation yourself by:
1. You can use your own custom request identifier via the TrueClient with TruecallerSDK.getInstance().setRequestNonce(customHash);
Note : The customHash must be a base64 URL safe string with a minimum character length of 8 and maximum of 64 characters
2. In ITrueCallback.onSuccesProfileShared(TrueProfile)
verify that the previously generated identifier matches the one in TrueProfile.requestNonce.
IMPORTANT: Truecaller SDK already verifies the request-response correlation before forwarding it to the your app.
6. Create a TruecallerSdkScope object by using the appropriate configurational settings and use it to initialise the TruecallerSDK in your android activity's onCreate method :
Copy
You will find complete details on the configuration options in the TruecallerSdkScope object as described above, and all the possible available values in the immediate next section of this documentation here.
Here, sdkCallback is an interface that you need to define in your app where you would get the success or failure callbacks. You will find details about the implementation in this section.
Please note, sdkOptions enables you to configure the verification capability of Truecaller SDK. If you want to use the SDK for verification of Truecaller users only, you should provide the scope value as TruecallerSdkScope.SDK_OPTION_WITHOUT_OTP
If you want to use the SDK for verification of Truecaller users as well as non-Truecaller users powered by Truecaller's drop call / OTP ( for implementation details, refer Verifying non-Truecaller users section ), you should provide the scope value as TruecallerSdkScope.SDK_OPTION_WITH_OTP
Truecaller SDK needs to be initialised only once and the same instance can be accessed at any place within your app, without the need to initialise it again, via TruecallerSDK.getInstance()
Initialising the SDK at more than one place can lead to undesired behaviour
Once you initialise the TruecallerSDK using the init() method, if you are using the SDK for verification of only Truecaller users ( by setting the sdkOptions scope as TruecallerSdkScope.SDK_OPTION_WITHOUT_OTP ), you can check if the Truecaller app is present on the user's device or not by using the following method
Copy
You can trigger the Truecaller profile verification dialog anywhere in your app flow by calling the following method
Copy
You can trigger the Truecaller profile verification dialog anywhere in your app flow by calling the following method
Copy
In case isUsable() method returns false, implying that Truecaller app is not present on the device, you can take the user to your app screen and continue with the verification flow for non-Truecaller users OR choose to use your own verification flow [ Refer image below ].
4 | "Desired permissions are missing" | When the requisite permissions are missing or not granted while making the verification request |
6 | “Sim state is not ready” | When the SIM state on the device is not ready |
7 | “Airplane mode is ON” | When the device is on airplane mode, hence causing missed call to not go through |
2 | "Phone number limit reached” | When the used mobile number has exceeded the maximum number of allowed verification attempts within a span of 24 hours from the time the first verification attempt was made |
2 | “Request id limit reached” | When the used device exceeds the maximum number of allowed verification attempts in a span of 24h |
2 | “Invalid partner credentials.” | When the partner key ( app key ) you have configured in your project is incorrect. Visit or basis the build in which you are facing the issue on |
2 | “Something went wrong: Failed to create installation.” | In case of Truecaller internal service error |
2 | “Invalid phone number” | When the input mobile number is not a valid mobile number |
2 | “Profile has not been created yet” | When the user has been successfully verified, but for some reason their profile is not created which could be due to incorrect profile data while creating TrueProfile() in verifyMissedCall method or due to network issues |
1. Ensure that your Minimum SDK version is at least API level 22 or above ( Android 5.1 ). In case your android project compiles for API level below 22, you can include the following line in your AndroidManifest.xml file to avoid any compilation issues :
Copy
Using this would ensure that the sdk works normally for API level 22 & above, and would be disabled for API level < 22 Please make sure that you put the necessary API level checks before accessing the SDK methods in case compiling for API level < 22
2. Add the following dependency in your app level build.gradle file :
Copy
Also, add the following lines of code in your gradle file, if not already present
Copy
Add mavenCentral() in your project level build.gradle file :
Copy
Please note that Truecaller SDK already contains consumer proguard rules, so it will be appended automatically to your app's proguard rules and you do not need to have any additional proguard rules to be added for the SDK to function.
Failure/ Error responses
The "onFailureProfileShared" callback method that you just implemented in the previous step helps you to handle all the possible failure cases when the user couldn't be verified successfully via the Truecaller flow.
Below are some of the possible failure scenarios and the corresponding error response that you receive for each of the cases :
*Error Type 4 and Error Type 10 could arise in different conditions depending on whether the user has not registered on Truecaller app on their smartphone or if the user has deactivated their Truecaller profile at any point of time from the app.
Apart from the above mentioned error cases, there are few other error scenarios that you may encounter under rare circumstances. For complete and exhaustive list of all the error cases, you can refer to TrueError.class within the SDK.
Please note that when you encounter any of the error scenarios and get the control in the "onFailureProfileShared()" method, you should redirect the user to your alternate verification flow.
Exceptions
In case you face any of the following run time exceptions, please follow the recommended steps as mentioned below :
"No compatible client available. Please change your scope"
As the exception suggests, you are trying to call an SDK method even though no client is available to handle it. This usually happens if you have initialised the SDK using WITHOUT_OTP scope option i.e to verify only the Truecaller users, and you are not calling isUsable()
method before calling an SDK method. To resolve this, call isUsable()
before calling any SDK method if you are using WITHOUT_OTP scope option
"Please call init() on TruecallerSDK first"
This exception suggests that you are trying to call an SDK method before the SDK has been initialised. To resolve it, check for all possible user flows in your app which could lead to calling an SDK method directly before it has been initialised.
Error Code
What it means
1
Network Failure
2
User pressed back
3
Incorrect Partner Key
4 & 10
User not Verified on Truecaller*
5
Truecaller App Internal Error
13
User pressed back while verification in process
14
User pressed footer CTA (" USE ANOTHER NUMBER")
15
To handle ActivityNotFound Exception, in case Truecaller app fails to initiate