Reputation: 6382
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.
Upvotes: 4
Views: 670
Reputation: 6382
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
Upvotes: 1
Reputation: 3407
Tracking call state seams the best way, because your question is off the track of android standard.
There is no official answer to your question because :
By the Android API there is no official way for a third party application provider to answer to a phone call because
1 : you've to use undocumented API.
2 : request MODIFY_PHONE_STATE permission is only available for rooted/system signed application since 2.3
So if an efficient(build in code) working answer exist for your question, it may officially not working for every manufacturer/model devices.
more info at How to grant MODIFY_PHONE_STATE permission for apps ran on Gingerbread
Upvotes: 1