I've been exploring Android's Telephony Manager a bit and fount out there is a way to listen to such events as ringing, off hook and idle. However, it's not enough for me...
When the call is actually initiated, I get an 'offhook' event, but I get nothing when the person I'm calling to, presses the 'Answer' button.
Is there a way to know EXACTLY when somebody actually pressed the Answer button when I call to him/her, in other words I want to know when somebody answers the call?
Any help\suggestions will be appreciated...
I don't think its possible. There's no such state/event at least I know of. So your best bet would be to stick with CALL_STATE_OFFHOOK.
Related
I need to start an action after a call has ended. No button clicks or anything like that, I need it for both incoming and outgoing calls. I understand I have to deal with PHONE_STATE_IDLE.
Does this mean I have to have listeners to listen to incoming and outgoing calls, and when they start and finally when the pgone goes IDLE after that?
Or is there a simpler way. I checked the Telephony docs from Android, but the 3 PHONE_STATE cases mentioned there are a bit vague for me.
Also , most answers related to this are both old and lead to a dead-end (for me, atleast). Anything concerning Marshmallow, or better yet Oreo, would be of great help.
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
The app I am developing needs to know when someone presses the End Call button. It doesn't need to alter the button's function at all. It merely needs to know when it is pressed. I would just like to know if this is possible and how to do this?
I have been looking at the KeyEvent class, but I am unable to implement it. I don't even know if it will work.
I highly doubt you can do this ... trapping key events that are not in your application is just malicious code.
Maybe you are interested in knowing if a call has been terminated?
If so: use the PhoneStateListener to detect state transitions from CALL_STATE_RINGING/CALL_STATE_OFFHOOK to CALL_STATE_IDLE
I would like to know how to intercept incoming calls and also how to forward them. I know there are several questions regarding this topic here and elsewhere on the net, but all the answers use the android.intent.action.PHONE_STATE action which is broadcast always after the phone begins to ring and the call screen is shown.
That's why I'm looking for a solution where i could intercept the call in an early stage before any notification (ringing etc..) has been done. I would like to know if maybe this is possible on a platform level in native code and if yes how ? Or perhaps with some kind of trick with the SDK ?
In general, if you can't do it in Java, you can't do it in the NDK. Most of the time the opposite is true: You can't do MOST things on Android in the NDK.
I don't know of a way to do that, and frankly doubt it exists: It would be a huge security hole if you could download an application that would forward calls to another number.
You may want to look at this source code, it may help you : http://code.google.com/p/auto-answer/
None of the existing apps in Android can forward a call based on a given number. All they can do is forward all or nothing. There's one app in particular (cBlocker) that can forward calls on schedule besides blocking incoming and outgoing calls and SMS based on rules.
"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