Implement Callbacks

7. Add the following condition in the onActivityResult method TruecallerSDK.getInstance().onActivityResultObtained( this,requestCode, resultCode, data)

Copy

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == TruecallerSDK.SHARE_PROFILE_REQUEST_CODE) {
       TruecallerSDK.getInstance().onActivityResultObtained(this, requestCode, resultCode, data);
    }
}

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

private final ITrueCallback sdkCallback = new ITrueCallback() {
    
     @Override
     public void onSuccessProfileShared(@NonNull final TrueProfile trueProfile) {
     }

     @Override
     public void onFailureProfileShared(@NonNull final TrueError trueError) {
     }
     
     @Override
     public void onVerificationRequired(@Nullable final TrueError trueError) {
     }
     
 };

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.

Last updated