0

I'm building an Android Dialer App and currently I'm working on a calling feature. The problem that I'm facing right now is when I'm already on a phone call and someone calls me, my app doesn't detect that there is another incoming call. I want to show user new incoming call on the calling screen during an active phone call. How can I detect that and show it to the user? Thanks!

I'm trying this to detect new incoming call but it doesn't work.

class CallActionReceiver : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
    var state = 0
    when (intent.getStringExtra(TelephonyManager.EXTRA_STATE)) {
        TelephonyManager.EXTRA_STATE_IDLE -> {
            state = TelephonyManager.CALL_STATE_IDLE
        }
        TelephonyManager.EXTRA_STATE_RINGING -> {
            state = TelephonyManager.CALL_STATE_RINGING
        }
        TelephonyManager.EXTRA_STATE_OFFHOOK -> {
            state = TelephonyManager.CALL_STATE_OFFHOOK
        }
    }
    if (lastState != state) {
        when (state) {
            TelephonyManager.CALL_STATE_RINGING -> {
                if (lastState == TelephonyManager.CALL_STATE_OFFHOOK) {
                    context.showToast("New Call In Waiting")
                }
            }
            TelephonyManager.CALL_STATE_IDLE -> {
                if (lastState == TelephonyManager.CALL_STATE_RINGING) {
                    context.showToast("Missed Call")
                }
            }
        }
    }
    lastState = state
    when (intent.action) {
        ACCEPT_CALL -> {
            context.startActivity(CallingActivity.getStartIntent(context))
            CallManager.accept()
        }
        DECLINE_CALL -> {
            CallManager.reject()
        }
    }
}

}

Hamza Sheikh
  • 179
  • 1
  • 9
  • showing code snippet of how you detect first call (and where you expect second call to appear) would be a good start – Pawel Nov 01 '22 at 11:55
  • I've added my code in my question. I'm trying to get it through this way but it doesn't work. – Hamza Sheikh Nov 02 '22 at 05:48

0 Answers0