How not to sunbathe PhoneStateListener.CALL_STATE_RINGING, if already talking, and the second caller is calling

I am programming an application that automatically answers a call. The problem is that he should not answer if I am already calling and someone is calling. Is there any way to achieve this?

According to the document, if I check the status with TelephonyManager , it will be CALL_STATE_RINGING , not CALL_STATE_OFFTHEHOOK .

Do I need to add a variable that is set in the changing state of the phone, so I know that there is an ongoing call or is there a better solution?

Thanks!

/ edit: I answer the call without the permission of Modify_Phone_State , so it only finds out that there is already a call.

+4
source share
2 answers

Well, since there seems to be no way to figure this out, I saved the boolean value in 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 that if RINGING starts when someone is already calling, I read that the variable is true, and then discards the following actions.

For those who want more information on how to answer a call, check out the AutoAnswer Project

+1
source

Tracking call status is best because your question is not Android standard.

There is no official answer to your question because:

There is no official way for the third-party application provider to answer the phone in the Android API because
1: you should use an undocumented API.
2: MODIFY_PHONE_STATE query is allowed only for applications with root / system signature with 2,3

So, if for your question there is an effective (embedded code) working answer, it may not officially work for each device manufacturer / model.

More Information on How to Grant MODIFY_PHONE_STATE Permission for Gingerbread Applications

+1
source

Source: https://habr.com/ru/post/1382560/


All Articles