Search code examples
androidtelephonymanager

How to not fire PhoneStateListener.CALL_STATE_RINGING if already talking and a second caller is calling


I am programming an app, that automatically answers a call. The problem is, that it should not answer one if I am already in a call and someone is ringing. Is there a way to achieve that?

According to the doc, if I check the status with TelephonyManager it would be CALL_STATE_RINGING and not CALL_STATE_OFFTHEHOOK.

Do I have to add a variable that is set true on a changing Telephone state so I know that there is an ongoing call or is there a better solution?

Thanks!

/edit: I answer the call without the permission Modify_Phone_State, so it is only about finding out if there is already a call ongoing.


Solution

  • Okay, so as there is apparently no way to figure this out, I stored a Boolean in a SharedPreference as soon as the State goes to OFFTHEHOOK (true).

    When the state changes to IDLE, I set the Boolean to false. So this means, if RINGING is fired while someone is already calling, I read out that the variable is true, and then discard the following actions.

    For those who want more information on how to answer a call, have a look at the AutoAnswer Project