title: How to accept an incoming call by clicking a button?
body: <p>I'm trying to implement my own phone call handling UI.</p>
  
  <p>What I want to do is, if a call comes in, the incoming telephone number and a picture are displayed, and, if I press a button, the incoming call will be accepted/answered. </p>
  
  <p>The related code is:</p>
  
  <pre><code> @Override
    public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      answerButton = (Button) findViewById(R.id.pickup);
      answerButton.setOnClickListener(new OnClickListener() {
          public void onClick(final View v) {
              Intent intent = new Intent("android.intent.action.ANSWER");
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              startActivity(intent);          
          }
      });
  </code></pre>
  
  <p>Sadly, the code does not work. At first, an exception is thrown if I press my answer button:</p>
  
  <blockquote>
    <p>ActivityNotFoundException: No Activity found to handle Intent {<br>
    act=android.intent.action.ANSWER</p>
  </blockquote>
  
  <p>Then I added an entry in the AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
  </code></pre>
  
  <p>I run the app again, there is no exception anymore. However, I doubt the incoming call is not really accepted. Because if the press the Android's screen answer button (green button), the incoming call is accepted and a green in call icon is also displayed on the upper left corner of the emulator screen, while my app doesn't.</p>
  
  <p>I also read the Phone app's source code in android source.  There is method such as acceptCall()  in the Phone class. But these codes seem difficult for me to use, because there are many imports declaration in the code, such as :</p>
  
  <pre><code>import com.android.internal.telephony.Call;
  import com.android.internal.telephony.CallStateException;
  import com.android.internal.telephony.CallerInfo;
  import com.android.internal.telephony.CallerInfoAsyncQuery;
  import com.android.internal.telephony.Connection;
  import com.android.internal.telephony.MmiCode;
  import com.android.internal.telephony.Phone;
  </code></pre>
  
  <p>And, if I add these imports in my code, there will be too many errors, such as :<br>
  <code>The import com.android.internal.telephony cannot be resolved</code>.</p>
  
  <p>What is the right and simple way for my problem?</p>