title: Detecting outgoing call answered on Android
body: <p>I know this has been asked many times already, with no answers, but I still hope that someone has finally solved the problem.</p>
  
  <p>The problem: I have a non-rooted device running Android 2.3. I need to create a service which:</p>
  
  <ol>
  <li>makes a phone call;  </li>
  <li>waits until the call is answered; </li>
  <li>hangs the phone after the call is answered (with a timeout);</li>
  </ol>
  
  <p>Like many others, I've got stuck with #2. Below is the summary of the solutions ever suggested:</p>
  
  <ul>
  <li>Use PhoneStateListener (most popular): does not work, for an outgoing call it cannot detect what I need.</li>
  <li>Use <code>com.android.internal.telephony.CallManager</code> and its methods like <code>registerForPreciseCallStateChanged</code> (e.g., <a href="https://stackoverflow.com/a/12042299/1491190">this one</a>): does not work, no phones are registered within it, so the events do not fire.</li>
  <li>Use <code>com.android.internal.telephony.PhoneFactory</code> to obtain a <code>com.android.internal.telephony.Phone</code> instance (which is the key to everything): does not work, the factory is not initialized; attempts to initialize it with a <code>makeDefaultPhones</code> call result in a security exception (like <a href="https://stackoverflow.com/q/6010796/1491190">here</a>).</li>
  <li>Detect the outgoing ringtone (<a href="https://stackoverflow.com/a/14892016/1491190">link</a>): the author - <a href="https://stackoverflow.com/users/742001/dany-poplawec">Dany Poplawec</a> - 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.</li>
  </ul>
  
  <p>It looks like everything has been tried already, but there still may be one more trick that will save me :)</p>