Reputation: 227
I am working on an App that should detect when Phone Call is placed on hold, all I can find in Android Telephony documentation is 3 states, that is CALL_STATE_RINGING when Phone is ringing, CALL_STATE_OFFHOOK When call is in progress or on Hold or CALL_STATE_IDLE when no call activity exists, but I would like to know, has anyone found out a way around to detect exactly when call is on Hold? I need to do some action only when call is on hold.
Upvotes: 2
Views: 2110
Reputation: 151
For anyone looking for a solution to detect the on-hold state without using PreciseCallState:
An on-hold state can occur if the phone transitions from OFFHOOK to RINGING and then back to OFFHOOK. This indicates that a new call came in while another call was already active.
Now, to detect whether the user rejected or accepted the new incoming call:
After the state changes from RINGING to OFFHOOK, I check the call log. If a new call appears in the call log with a status of rejected, I know that the user didn't put the active call on hold. If the call log doesn't show a new entry, it means the user has put the active call on hold.
I handle all phone states with a Broadcast Receiver. From the receiver, I run my foreground service class to manage the call logs, make API requests, and perform other operations.
Upvotes: 0
Reputation: 6855
This is possible in Android 5.0 using the The PreciseCallState, You can read call state such as idle,busy and ringing.GithubCode PreciseCallStateDetail
Upvotes: 1
Reputation: 1715
Take a look at this answer https://stackoverflow.com/a/29490832/3836513 . Using PreciseCallState you can read when call is put on hold.
Upvotes: 1