简体   繁体   中英

Opentalk(Vonage) API set callertune for detect phone call ringing

How to detect the time when a phone starts ringing for outgoing calls.I am developing an application in which i am trying to make a call programatically and when call is connected to inte.net like whats app audio call app.i didnt found the solution how to detect call is ringing or busy to reciever side. i connect my call using token key and session key through inte.net. my code is below for passing intent to call activity.

val intent = Intent(this@AstroDetailsActivity, CallActivity::class.java)
                intent.putExtra(SESSION_ID_KEY, res!!.session_id)
                intent.putExtra(TOKEN_KEY, res.token)
                intent.putExtra("userId", MyApplication.sharedPreference?.userId.toString())
                intent.putExtra("astroId", astroId)
                intent.addCategory(Intent.ACTION_CALL)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

                startActivity(intent)

The example code doesn't make use of intent extras so I am unsure if you have made changes to this code to actually initialise.

But if you look in this activity you will see a PhoneStateListener . This object is attached to a call using:

private fun registerPhoneListener() {
    val telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
}

The PhoneStateListener then has a method onCallStateChanged which gets called when the current state of a phone call is changed. This can be overidden to carry out custom logic as below:

private val phoneStateListener: PhoneStateListener = object : PhoneStateListener() {
    override fun onCallStateChanged(state: Int, incomingNumber: String) {
        super.onCallStateChanged(state, incomingNumber)

        when (state) {
            TelephonyManager.CALL_STATE_IDLE -> {
                publisher?.publishVideo = true
                publisher?.publishAudio = true
            }
            TelephonyManager.CALL_STATE_RINGING -> Log.d("onCallStateChanged", "CALL_STATE_RINGING")
            TelephonyManager.CALL_STATE_OFFHOOK -> {
                Log.d("onCallStateChanged", "CALL_STATE_OFFHOOK")
                publisher?.publishVideo = false
                publisher?.publishAudio = false
            }
            else -> Log.d("onCallStateChanged", "Unknown Phone State !")
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM