Verifying non Truecaller users

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 / OTP SMS ( Currently available only for India )

In order to verify non Truecaller users, the SDK requires the below mentioned permissions -

For Android 8 and above :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
For Android 7 and below :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>

These permissions are required for the SDK to be able to automatically detect the drop call and complete the verification flow. In case your app doesn't prompt the user for these permissions before invoking the verification flow, the SDK would trigger the permission prompt to the user at the time of verification and hence you need to override onRequestPermissionsResult()to pass the permissions results back to the SDK like this

@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions,
@NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

In case these permissions are not granted to your app by the user, the SDK would fallback to use OTP as the verification medium to complete the verification.

Once you receive a callback in the ITrueCallback#onVerificationRequired(), you can initiate the verification for the user by calling the following method:

TruecallerSDK.getInstance().requestVerification("IN", PHONE_NUMBER_STRING, apiCallback, ExampleActivity.this);

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 10-digit mobile number

  • 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.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

static final VerificationCallback apiCallback = new VerificationCallback() {
@Override
public void onRequestSuccess(int requestCode, @Nullable VerificationDataBundle extras) {
if (requestCode == VerificationCallback.TYPE_MISSED_CALL_INITIATED) {
}
if (requestCode == VerificationCallback.TYPE_MISSED_CALL_RECEIVED) {
}
if (requestCode == VerificationCallback.TYPE_OTP_INITIATED) {
}
if (requestCode == VerificationCallback.TYPE_OTP_RECEIVED) {
}
if (requestCode == VerificationCallback.TYPE_VERIFICATION_COMPLETE) {
}
if (requestCode == VerificationCallback.TYPE_PROFILE_VERIFIED_BEFORE) {
}
}
@Override
public void onRequestFailure(final int requestCode, @NonNull final TrueException e) {
}
};

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 OTP is successfully triggered for the input mobile number. In this case, you will get the requestCode as VerificationCallback.TYPE_OTP_INITIATED

  • When OTP is successfully detected on that device by the SDK present in your app. In this case, you will get the requestCode as VerificationCallback.TYPE_OTP_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

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