Detect Call On Hold - android

I wanted to know if there is any definitive way to know if the call is put on hold by the receiver on the receiver side only.
Now I checked the Telephony documentation, and this shows that there are three states for a call :
CALL_STATE_IDLE: When no call activity is there
CALL_STATE_RINGING: When a new call is ringing and waiting to be taken up.
CALL_STATE_OFFHOOK: At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.
Here lies the problem, OFFHOOK takes the active and hold state as one. There seems to be no way to distinguish between them.
But an interesting observation I made was that dialler recieves a notification when the call is retrieved from hold, that means there exists some way to know the difference. Hence, I would be obliged if you assist me in finding that way.

It looks like the current Telephony APIs doen't let you read the precise call state.
In this commit, however
https://github.com/android/platform_frameworks_base/commit/c5ac15a3e11c03951e269b243674858411204b67
You can see a proposal for a precise call state monitoring.
https://android-review.googlesource.com/#/c/60660/
Here you can see that at Feb 13 5:26 AM this "Change has been successfully merged into the git repository."
This means that sooner or later we'll see it in a future Android release.

Related

Detecting if call is on hold in Android

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.
Take a look at this answer https://stackoverflow.com/a/29490832/3836513 . Using PreciseCallState you can read when call is put on hold.
This is possible in Android 5.0 using the The PreciseCallState, You can read call state such as idle,busy and ringing.GithubCode PreciseCallStateDetail

(Reflective) Method call delivers same old results until app is force stopped and restarted (...is there something automatically cached somehow?)

I have a strange problem and hope that someone of you has an idea what happens here.
My app structure is as follows:
I have a main service which registers a broadcast receiver and listens to intents like screen on/off etc. So this service runs indefinitely.
When such an intent is received, I start another service which does the action
Inside this action service I launch an AsyncTask to fetch battery related stats via reflection. After the service is done, it calls stopSelf().
So everything works as expected, except that when the battery related infos have been fetched one time, each subsequent call of the AsyncTask/Reflection methods deliver exactly the same result which has been delivered before.
The battery stats have of course been updated in the meantime, but I do not get the new updated numbers, but always the stats from the first method call.
That is until I go to settings and force stop and restart my app, then I get updated battery statistics again, at least one time, because after that I'm stuck with these numbers again.
So my question:
Could it be that the results of the reflection call are automatically cached somewhere and that each subsequent call doesn't really fetch the new data but just delivers some cached results? What else could be the problem?
I'm thankful for any ideas, I you need some code lemme know :)
Ok, I've found a fix to this :))
The library of Better Battery Stats uses the singleton pattern for a needed class.
It also includes an invalidate() function, which sets the singleton instance to null, so that at the next getInstance() it gets reinitialized.
I'm using now invalidate after each statisitics fetch, and now I get the updated statistics on every call. Although I am still not sure why the Singleton pattern seems to be the root of this issue, it should also work with having one initialized singleton instance...
Well, one does not simply have to understand everything ;-)

How do I know who ended the call in Android - User or Remote User?

I want to specifically know who ended the call. I have setup a broadcast receiver for
"android.intent.action.PHONE_STATE"
When I detect a transition from Off hook to idle, I know the call has ended. But how do I know who ended the call?
Thanks a ton!
I'm afraid there's presently no way to determine if the user pressed "end call" or if the other end (or ends, in a group call) terminated. The only workaround I can suggest is monitoring the other states to observe if the phone state ringing was encountered. In such a case, you could assume the user is making the phone call as opposed to receiving it.
Bear in mind that there are other problems related to PHONE_STATE, such as handling multiple calls simultaneously.
In retrospect, I'm not entirely sure what you mean with "who". As for other apps ending the call: there is no official API to end phone calls; only through reflection can an app invoke the TelephonyService's endCall() function. Here, too, it is not possible to determine if the call was terminated through user interaction or not.

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

Categories

Resources