简体   繁体   English

Android 检测到电话不成功,稍后再试

[英]Android detect unsuccessful phone call and try again later

Is there a way to retry a missed or unsuccessful outbound phone call after a period of time?有没有办法在一段时间后重试错过或不成功的呼出电话? I am initiating a phone call using the ACTION_CALL intent and have it connected to a PhoneStateListener.我正在使用ACTION_CALL意图发起电话呼叫并将其连接到 PhoneStateListener。

class PlaceCall : AppCompatActivity() {
    private fun outboundCall() {
        val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
        telephonyManager.listen(CallListener(context), PhoneStateListener.LISTEN_CALL_STATE)
        val callIntent = Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber))
        startActivity(callIntent)
    }
}

CallListener is setup like this: CallListener 设置如下:

class CallListener(cont: Context) : PhoneStateListener() {
    private var context: Context = cont
    private var incoming: Boolean = false
    private var prevState: Int = TelephonyManager.CALL_STATE_IDLE

    override fun onCallStateChanged(state: Int, phoneNumber: String?) {
        val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
        when(state) {
            TelephonyManager.CALL_STATE_RINGING -> { incoming = true }
            TelephonyManager.CALL_STATE_IDLE -> {
                if(prevState == TelephonyManager.CALL_STATE_RINGING) { //Missed call?
                }
            TelephonyManager.CALL_STATE_OFFHOOK -> { Log.d("DEBUG", "calling $phoneNumber") }
            }
        }
        prevState = state
    }
}

How can I wait a determined interval and try the call again if it is anything other than a successful phone call connection?如果不是成功的电话呼叫连接,我如何等待确定的时间间隔并再次尝试呼叫? Also, why is the value of phoneNumber in the listener always empty?另外,为什么监听器中phoneNumber的值总是空的?

Unlike an incoming call which goes through IDLE -> RINGING -> OFFHOOK , in outbound calls it always jumps directly from IDLE -> OFFHOOK even while it's ringing (on the other side).与通过IDLE -> RINGING -> OFFHOOK的来电不同,在出站呼叫中,即使在响铃时(在另一侧),它也总是直接从IDLE -> OFFHOOK跳转。

So if by "successful" you mean to say a phone call that had been picked up by the other side, PhoneStateListener won't help you, as there's no additional state sent when the other side picks up.因此,如果您所说的“成功”是指对方接听的电话, PhoneStateListener不会帮助您,因为对方接听时不会发送额外的 state。

Also, why is the value of phoneNumber in the listener always empty?另外,为什么监听器中phoneNumber的值总是空的?

phoneNumber is populated for incoming calls only, and only if you app has both READ_CALL_LOG and READ_PHONE_STATE permissions, see here . phoneNumber仅为来电填充,并且仅当您的应用同时具有READ_CALL_LOGREAD_PHONE_STATE权限时, 请参见此处

If you need to last called number you can use the Calls.getLastOutgoingCall API a few seconds after an outgoing call has ended.如果您需要最后一个被叫号码,您可以在拨出电话结束几秒钟后使用Calls.getLastOutgoingCall API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测android中的电话呼叫广播接收器 - how to detect phone call broadcast receiver in android Android:连接时电话呼叫检测? - Android : Phone call detect when connected? 发生错误。 请稍后再试 - An error occured. Please try again later Android版Facebook SDK“ MyApp发生错误。 请稍后再试” - Facebook SDK for Android “An error has occurred with MyApp. Please try again later” “目前无法下载。 尝试从android应用中的图库加载图像时,请稍后重试” - “Currently unable to download. Please try again later” when trying to load image from gallery in android app Android Facebook SDK 3.0登录错误 - 发生错误。 请稍后再试 - Android Facebook SDK 3.0 Login error - An error occurred. Please try again later 登录错误:登录此应用程序时出错。 请稍后在 flutter 中重试 android 模块 - Login Error : there is an error in logging you into this application. please try again later in flutter for android module Android-托管的Google Play控制台IAP发生意外错误。 请稍后再试。 (1200001) - Android - Managed Google Play Console IAP An unexpected error occurred. Please try again later. (1200001) 如何使用 React Native 检测 Android 手机中的电话? - How to detect a phone call in Android phone with React Native? Android:在通话期间检测当前处于活动状态的电话号码 - Android: Detect currently active phone number during phone call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM