- Request permissions needed by SDK to intercept the incoming flashcall automatically.
- Proceed with the verification flow with the number typed by the user.
package com.sinch.rtc.flashcall.gettingstarted
import android.Manifest
import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.sinch.rtc.flashcall.gettingstarted.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
companion object {
const val PERMISSION_REQUEST_CODE = 5
}
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(LayoutInflater.from(this))
setContentView(binding.root)
binding.initButton.setOnClickListener {
ActivityCompat.requestPermissions(
this, arrayOf(
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.READ_CALL_LOG
), PERMISSION_REQUEST_CODE
)
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
//We simply proceed with the verification
VerificationDialog.newInstance(binding.phoneInputEditText.text.toString())
.apply {
show(supportFragmentManager, "dialog")
}
}
}
Although the SDK can work without all the permissions being granted by the user, for best user experience, we highly recommend requesting these as in such a case the incoming phone call can be automatically intercepted by the SDK and reported to the Sinch Platform. MainActivity.kt
code snippet shows how to request them and proceed with the verification once all of them are granted. Permissions requested here should also be listed in the AndroidManifest.xml
file. You can read more about Android permissions here.
For simplicity we simply pass the number typed by the user without any reformatting or validation.
binding.phoneInputEditText.text.toString()
In order the verification to succeed the number must be in E.164 Format, e.g. Netherlands 0639111222 -> +31639111222. See phone numbers section to read more about phone numbers handling. Note that as long as you're using a test account you have to add the number you're trying to verify to your verified numbers tab in the dashboard.
Once we have the number to be verified and required permissions granted it's time to initiate your first flashcall verification request!
Learn more about the Verification API: