4

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.

Force
  • 6,312
  • 7
  • 54
  • 85

2 Answers2

1

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

Community
  • 1
  • 1
Emmanuel Devaux
  • 3,327
  • 4
  • 25
  • 30
  • Actually I am not using the Modify_Phone_State permission, but emulating a bluetooth headset kepress that answers the call without a permission in the android manifest ;-) – Force Nov 23 '11 at 09:35
  • 1
    Nice trick! In my answer I didn't expect this kind of way to hang up/down a phone call .. – Emmanuel Devaux Nov 23 '11 at 13:59
1

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

Force
  • 6,312
  • 7
  • 54
  • 85