# Initiate a Flashcall verification request with Android Verification SDK In this guide you will see: 1. How to [configure the verification SDK.](#create-global-configuration) 2. Logic needed to [initiate a single flashcall verification request.](#initiate-flashcall-verification) 3. How SDK [reports the verification](#report-flashcall-verification-result) to Sinch Platform. ## Create global configuration VerificationDialog.kt package com.sinch.rtc.flashcall.gettingstarted import android.app.Dialog import android.os.Bundle import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment import com.sinch.rtc.flashcall.gettingstarted.databinding.DialogVerificationBinding import com.sinch.verification.core.auth.BasicAuthorizationMethod import com.sinch.verification.core.config.general.SinchGlobalConfig import com.sinch.verification.core.internal.Verification import com.sinch.verification.core.verification.VerificationEvent import com.sinch.verification.core.verification.response.VerificationListener import com.sinch.verification.flashcall.FlashCallVerificationMethod import com.sinch.verification.flashcall.config.FlashCallVerificationConfig import com.sinch.verification.flashcall.initialization.FlashCallInitializationListener import com.sinch.verification.flashcall.initialization.FlashCallInitializationResponseData import java.util.* class VerificationDialog : DialogFragment(), VerificationListener { companion object { private val TAG = VerificationDialog::class.java.simpleName private const val APP_KEY = "" private const val APP_SECRET = "" // don't keep app secret ind SDK code while using production environment private const val PHONE_NUMBER_TAG = "phone_number" fun newInstance(phoneNumber: String) = VerificationDialog().apply { arguments = Bundle().apply { putString(PHONE_NUMBER_TAG, phoneNumber) } } } private var _binding: DialogVerificationBinding? = null // This property is only valid between onCreateView and // onDestroyView. private val binding get() = _binding!! private val initListener = object : FlashCallInitializationListener { override fun onInitializationFailed(t: Throwable) { showErrorWithMessage(t.message.orEmpty()) } override fun onInitiated(data: FlashCallInitializationResponseData) { Log.d(TAG, "Verification Initiated") } } private lateinit var verification: Verification override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) //Normally we would implement all the logic inside View Model but for simplicity we will keep it here. val globalConfig = SinchGlobalConfig.Builder.instance.applicationContext( requireContext().applicationContext ) // Basic authorization should be used for test purposes only //.authorizationMethod(BasicAuthorizationMethod(APP_KEY, APP_SECRET)) .authorizationMethod(AppKeyAuthorizationMethod(APP_KEY)) .build() verification = FlashCallVerificationMethod.Builder().config( FlashCallVerificationConfig.Builder().globalConfig(globalConfig) .number(arguments?.getString(PHONE_NUMBER_TAG).orEmpty()) .build() ) .initializationListener(initListener) .verificationListener(this) .build() } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return super.onCreateDialog(savedInstanceState).apply { isCancelable = false } } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { _binding = DialogVerificationBinding.inflate(inflater, container, false) return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.verifyButton.setOnClickListener { verification.verify(binding.codeInput.editText?.text.toString()) } binding.quitButton.setOnClickListener { verification.stop() dismiss() } verification.initiate() } override fun onDestroyView() { super.onDestroyView() _binding = null } override fun onVerified() { binding.progressBar.hide() binding.messageText.apply { setTextColor(context.getColor(R.color.green)) text = getString(R.string.successfullyVerified) binding.quitButton.text = getString(R.string.close) binding.codeInput.visibility = View.GONE binding.verifyButton.visibility = View.GONE } } override fun onVerificationFailed(t: Throwable) { showErrorWithMessage(t.message.orEmpty()) } override fun onVerificationEvent(event: VerificationEvent) {} private fun showErrorWithMessage(text: String) { binding.progressBar.hide() binding.messageText.apply { setTextColor(context.getColor(R.color.red)) this.text = String.format(Locale.US, getString(R.string.verificationFailedPlaceholder), text) } } } The global configuration object is used to provide properties that will be used by multiple verification attempts. You'll most like need to create only one such object and share it between multiple verification requests. Parameters that might be passed into it's builder are listed below: | Parameter | Your value | | --- | --- | | `applicationContext` | The application context bound to your Android application. (required) | | `authorizationMethod` | Authorization method that will be used to sign your requests when communication with Sinch Platform. (required) | | `apiHost` | The Sinch REST API endpoint (optional, defaults to `https://verification.api.sinch.com/`) | | `interceptors` | List of OkHttp interceptors that might be provided if you want to include some custom logic when sending HTTP requests to Sinch Platform. Read more about OkHttp interceptors [here](https://square.github.io/okhttp/features/interceptors/). (optional) | The code snippet listed here showcases `BasicAuthorizationMethod` and `AppKeyAuthorizationMethod`. `BasicAuthorizationMethod` should only be used for testing purposes to bootstrap your application as soon as possible. For production ready codebase `AppKeyAuthorizationMethod` should be used in cooperation with callback sent to the backend. In order to use it modify the parameters listed below with values copied from your app's dashboard [Apps](https://dashboard.sinch.com/verification/apps) section. | Parameter | Your value | | --- | --- | | `appKey` | The application key bound to your application. (required) | | `appSecret` | The application secret bound to your application. It should be used only for testing purposes. Application secret should never be provided for SDK in production environment. | ## Initiate Flashcall verification Similarly to what we've done before when creating global configuration, this time we'll have to create verification specific configuration. Parameters that are accepted by the builder of flashcall method are listed below: | Parameter | Your value | | --- | --- | | `globalConfig` | The global configuration object created before. (required) | | `number` | Number in E.164 Format to be verified. (required) | | `custom` | The `custom` string field that can be used to pass verification specific data. Look [here](/docs/verification/api-reference/verification/verifications-start/startverification#verifications-start/startverification/t=request&path=&d=0/custom) for more information. (optional) | | `reference` | String that used as a reference in the requests for tracking purposes. Look [here](/docs/verification/api-reference/verification/verifications-start/startverification#verifications-start/startverification/t=request&path=&d=0/reference) for more information. (optional) | | `honourEarlyReject` | Flag indicating if the verification process should honour early rejection rules.. See [Early reject](/docs/verification/android/android-the-verification-process/#early-reject) reference for more information. (optional) | During the verification process you'll be notified by the SDK about the verification process state by: | Parameter | Your value | | --- | --- | | `initiationListener` | This listener will be invoked with the result of the verification initiation request. If it's `onInitiated` callback is invoked you can assume that Sinch Verification Platform attempted to verify the given number by issuing a flashcall. Otherwise `onInitializationFailed` is invoked with an error parameter describing what went wrong (required) | | `VerificationListener` | The listener that is used to either notify the client about successful verification by invoking `onVerified` callback or a failure during the process by calling `onVerificationFailed`. (required) | When your verification object is built simply call `verification.initiate()` to start the verification process!. ## Report flashcall verification result After you've initialized your verification you'll see the following events happening: 1. If the initiation process succeeded you should see `Verification Initiated` being logged in the Android Studio logcat output. 2. Few seconds after that you'll see an incoming phone call that will be automatically intercepted by the SDK and reported back to Sinch Platform. 3. Finally, you should see an Android alert being presented on your application screen informing that the verification was successful. In a real life use case, after that verified user of your application would be allowed to log into his account. Note: Due to the permissions being granted to the app initially, the SDK was able to intercept the call automatically and pass the verification code (which in case of flashcall verification is the number that you're receiving the call from) back to the framework. If for some reason that fails, the verification code can be reported manually by calling `verification.verify` method and passing the number you're receiving the call from as an argument. ## Additional resources Learn more about the Verification API: - [API specification](/docs/verification/api-reference/verification)