Question

I have an application that needs to check whether there is an ongoing call from a specific contact.

I know I can use the ACTION_PHONE_STATE_CHANGED broadcast intent to get the calling phone number at the CALL_STATE_RINGING, but what I'd like to do is to use the TelephonyManager.getCallState function and in case there is an active call (CALL_STATE_RINGING or CALL_STATE_OFFHOOK), to get the caller phone number.

Any ideas ?

Was it helpful?

Solution

So, After further investigating this I'm now sure that there is no easy way for it...

What I finally done was listen to the ACTION_PHONE_STATE_CHANGED and NEW_OUTGOING_CALL broadcast intent and when I receive them, register a sticky broadcast (one that I created) that contains an extra with the phone number and an indication if its an incoming or outgoing call. I remove that sticky intent when I get a ACTION_PHONE_STATE_CHANGED with CALL_STATE_IDLE).

Now when I need to know if there is an active call, I try getting that sticky broadcast (registerReciever with null receiver) and if there is a sticky available, I can get the phone number and an indication of an incoming/outgoing call.

One thing that still can be improved is better handling of a waiting call since ACTION_PHONE_STATE_CHANGED will be received during an active call and I can't say which is active (see related question)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top