问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/11031590/how-to-get-outgoing-call-connected-state