title: How do I get a Phone instance in android?
body: <p>I have to use android ITelephony the internal classes on android telephony. I am using ITelephony to make calls by getting its instance as</p>
  
  <pre><code>ITelephony phone = ITelephony.Stub.asInterface(
      ServiceManager.getService(Context.TELEPHONY_SERVICE)
  );
  </code></pre>
  
  <p>and then calling with</p>
  
  <pre><code>phone.call(destNum);
  </code></pre>
  
  <p>Now I need to perform other actions like holding a call. ITelephony does not provide an API for this, but I found a Phone class that has <code>switchHoldingAndActive()</code>, but to call this I need a Phone instance to the currently running active call. I tried  </p>
  
  <pre><code>Phone PhoneActive = PhoneFactory.getDefaultPhone();
  </code></pre>
  
  <p>but its giving me an exception saying </p>
  
  <pre class="lang-none prettyprint-override"><code>Caused by: java.lang.RuntimeException: 
    Can't create handler inside thread that has not called Looper.prepare()
  </code></pre>
  
  <p>What is the correct way to get a Phone Instance?</p>