I know this has been asked many times already, with no answers, but I still hope that someone has finally solved the problem.
The problem: I have a non-rooted device running Android 2.3. I need to create a service which:
- makes a phone call;
- waits until the call is answered;
- hangs the phone after the call is answered (with a timeout);
Like many others, I've got stuck with #2. Below is the summary of the solutions ever suggested:
- Use PhoneStateListener (most popular): does not work, for an outgoing call it cannot detect what I need.
- Use
com.android.internal.telephony.CallManager
and its methods likeregisterForPreciseCallStateChanged
(e.g., this one): does not work, no phones are registered within it, so the events do not fire. - Use
com.android.internal.telephony.PhoneFactory
to obtain acom.android.internal.telephony.Phone
instance (which is the key to everything): does not work, the factory is not initialized; attempts to initialize it with amakeDefaultPhones
call result in a security exception (like here). - Detect the outgoing ringtone (link): the author - Dany Poplawec - states that detecting ringtones may help to solve the problem, but does not provide any details, so I was not able to try this technique.
It looks like everything has been tried already, but there still may be one more trick that will save me :)