Out going call answered state in Android 2.2+ - android

In my application I initiated an outgoing call and I am using PhoneStateListener to know about call state.
Whenever I start making call the phone state is TelephonyManager.CALL_STATE_OFFHOOK. When call recipient answered the call, I am not getting any change in phone's state.
I tried many but failed to get this answered state. Somebody told use bluetooth's HFP (Hands Free Profile) to get call answered state. But I didn't get any information about HFP from android developers website.
If anybody faced same problem and got the solution, please give your valuable suggestions.

The CALL_STATE_OFFHOOK doesn't change when the call is answered by the recepient:
Device call state: Off-hook. At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.
The state shouldn't change as long as the phone is in call, whether it's answered or not.
This question had been asked many items, and so far none of the those I found have been solved: Detect if an outgoing call has been answered, Android : How to get a state that the outgoing call has been answered?, Android : How to get a state that the outgoing call has been answered? (There are many others). The solutions provided there rely on the CALL_STATE_OFFHOOK state to change when the call is answered, which doesn't happen.
Seems like there is no public API which can be used to get the outgoing call state. The best workaround I see is what Vivek Khandelwal suggested., it's not so long to code nor has heavy performance overheads. Unless adding too many permissions (Now you need to add READ_CALL_LOGS) is a problem, use it.

I too had the same problem. This may not be the answer for your question. I am just sharing what I did.
I had an activity which opens the Contact and can make a call. What I wanted is, to known whether the call was successful (i.e recipient answered to the call).
There was no solution i found at that time with PhoneStateListener.
So as a work around, what I did is checked the Call Logs if it has a outgoing call to the phone numbers of that contact after starting the Contact Activity.
See if his help.

you want something specific to bluetooth? Otherwise I can provide sources

Related

Detect if a call has been answered and if not make another call to another number

I am making an application that would be connected to a headset and when pressing the central button makes a call.
The problem would be that if that call is not answered I should redial another number but I've been looking and it is not possible to know if the other person answered the call or not, only if it has been made, just finished or there is no call in progress.
Is it possible to perform the action I need, right now I am using phoneStateListener.

How to get outgoing call connected state

In my application development, I need to do vibration when outgoing call connected, but I can not get the call answered state. I have read some topic about this question, such as:
Outgoing call status
But actually, these questions not be answered correctly. Use BroadcastReceiver can only receive idle, offhook, ringing states, but no active state.
The active state defined in Call.java in internal framework, I have no idea to get this state. I did use reflection method, almost same as https://stackoverflow.com/questions/5652660/accessing-callmanager-in-android, But failed also.
I never tried with outgoing calls but with incoming calls you can play with the THREE STATES YOU'VE mentioned.
STATE_RINGING: call is ringing.
STATE_OFF_HOOK: if the previous state was RINGING, the call got connected.
STATE_IDLE: if prev state was RINGING: Call rejected. If prev state was OFF_HOOK call connected and then disconnected (i.e. completed).
I have code for this implementation for incoming calls. Since you mentioned you can access these states in outgoing calls as well, I think this should work for outgoing calls as well. If you want I can post my code.
After wondering and spending a lot of time on the net I found a way to achieve this...
Just query the call history of the device based on time of your last dialed call, fetch the duration of that call, if found greater than 0 that means your call was accepted and it works perfect.
if someone unable to get it, lets me know I will elaborate it with code.

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.
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
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

How to differentiate between a missed call and an refuse to answer?

I am designing an application in which I need to differentiate between a call rejected by the receiver (by pressing the dialing button) with the one not answered and is disconnected by the one who is dialing. is there anything that makes a differentiation since both of these come under the missed call category in Android?
You are lacking some details; please advise.
Are you referring to the Call Log provider android.provider.CallLog.Calls? There are only 3 call types defined. Can you provide the data of all the fields for such a Call Log entry?
The only other way (we know of) to tell is to watch the Phone State (via IntentReceiver) and track the transitions yourself. Most likely, a transition of Ringing to Idle would indicate the call was refused instead of answered, in which case it would transition Ringing to Offhook.

How to hang up (disconnect, terminate,..) incomings call?

"How do you hang up incoming calls (in Android of course)?"
First, I know this question has been asked and answered several times, and the response is always "you can't". But if we look in the market we get a few applications (all private software, no access to the source code... :-( ) that do this action, such as CallFilter, Panda firewall and others...
So... does somebody know how these apps do the hang up action, (or terminate, or disconnect or whatever you call it..)?
And other question, if the first don't get a response.. does somebody know how send an incoming call to the voice mail?
Of course, all questions are about how to do it programmatically. So with the voicemail question I know there's a flag in contacts that is used for that, but like I said, I'd like to know the programmatical way.
Thanks all!
Edit 1:
I have been seeing the LogCat traces using the application CallFilter and one trace seems to be interest, when it receives an incoming call, the PHONE_STATE is CALL_STATE_RINGING and fast appears one trace:
"05-03 19:32:34.416: INFO/UsageStats(78): Something wrong here, didn't expect com.android.phone to be paused"
and when CallFilter have done whatever do new trace "05-03 19:32:34.486:
INFO/UsageStats(78): Unexpected resume of com.android.phone while already resumed in com.android.phone"
appear, so i think CallFilter do something in one object com.android.phone, but i don't know how access to this.. any idea??
Edit 2:
I have performed at other times, and i don't see anymore the log traces above, so can be that the above may be that this does not mean anything.. i'm not sure..
the CallFilter application simply show one sec the incoming call, and then hang up.. how they do!!!???
I don't know how to hang up incoming calls, not sure if it's possible.
You can, i think, enter airplane mode programmatically, but it's a brutal method and really not advised. Changing such a setting should be done only by the user when he chooses to.
You may try using this API:
http://www.androidjavadoc.com/0.9_beta/com/android/internal/telephony/ITelephony.html

Categories

Resources