1

I have an app which plays audio. The thing is, when I get a call on my phone while I am interacting with the app, the audio continues to play. This becomes a problem because the audio makes it hard to understand what the person is saying. Is there any method that gets called when the user is talking on a call? That way I can mute my audio there. I have thoroughly researched the activity life cycle, but cannot find anything that will help me with this issue. I really appreciate all of your expert advice.

I have tried to put this code into my BaseActivity which gets extended by all other activities:

PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_RINGING) {
                //Incoming call: Pause music

                TwentySeconds.stopTimer();
                Intent i = new Intent(BaseActivity.this, FinishedBeforeTimer.class);
                startActivity(i);

                Toast.makeText(BaseActivity.this, "INCOMING CALL", Toast.LENGTH_SHORT).show();

            } else if(state == TelephonyManager.CALL_STATE_IDLE) {
                //Not in call: Play music
            } else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
                //A call is dialing, active or on hold

                TwentySeconds.stopTimer();
                Intent i = new Intent(BaseActivity.this, FinishedBeforeTimer.class);
                startActivity(i);

                Toast.makeText(BaseActivity.this, "DIALING", Toast.LENGTH_SHORT).show();
            }

But then the strangest thing happens. When I call the my phone, the phone I am calling with says that I can't call my phone. I am confused as to what to do now, I really appreciate your time.

Thanks,

Rich

Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83

0 Answers0