Opentalk(Vonage) API 设置 callertune 用于检测电话铃声

发布于 2025-01-18 20:23:50 字数 678 浏览 3 评论 0原文

如何检测电话开始响铃拨出电话的时间。我正在开发一个应用程序,在该应用程序中我试图以编程方式拨打电话,并且当呼叫连接到互联网时,例如“什么应用程序音频呼叫应用程序”。我没有找到解决方案检测到接收方的呼叫正在响铃或忙。 我通过互联网使用令牌密钥和会话密钥连接我的呼叫。我的代码如下,用于传递调用活动的意图。

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)

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 internet 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 internet. 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抠脚大汉 2025-01-25 20:23:50

示例代码 没有使用意图附加功能,所以我不确定您是否已对此代码进行了更改以实际初始化。

但如果您查看此 Activity,您将看到一个 PhoneStateListener。该对象使用以下方式附加到呼叫:

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

PhoneStateListener 然后有一个方法 onCallStateChanged,当电话呼叫的当前状态发生更改时,该方法将被调用。可以覆盖它以执行自定义逻辑,如下所示:

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 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 !")
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文