10

I'm trying to implement my own phone call handling UI.

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.

The related code is:

 @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);          
        }
    });

Sadly, the code does not work. At first, an exception is thrown if I press my answer button:

ActivityNotFoundException: No Activity found to handle Intent {
act=android.intent.action.ANSWER

Then I added an entry in the AndroidManifest.xml:

<uses-permission android:name="android.permission.CALL_PHONE" />

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.

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 :

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;

And, if I add these imports in my code, there will be too many errors, such as :
The import com.android.internal.telephony cannot be resolved.

What is the right and simple way for my problem?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Armstrong
  • 141
  • 2
  • 3
  • 7
  • see the link: [http://mylifewithandroid.blogspot.com/2008/01/phonecalls.html](http://mylifewithandroid.blogspot.com/2008/01/phonecalls.html) –  Sep 16 '11 at 07:05

5 Answers5

1

Add the category "android.intent.category.DEFAULT" (Intent.CATEGORY_DEFAULT)

gvaish
  • 9,374
  • 3
  • 38
  • 43
  • Thank you, MasterGaurav! But I've already added the category "android.intent.category.DEFAULT" in the manifest file. Here is the code: So I wonder there are other reasons. – Armstrong May 07 '10 at 07:24
1

The intent android.intent.action.ANSWER is somehow not working as expected. There is a workaround by emulating the bluetooth button to answer the incoming call. You can see an example from auto-answer project.

LewCPE
  • 46
  • 3
0

This is possible using the com.android.internal.telephony package, but you have to find someway for using this methods in eclipse and your app has to be compiled as a system app using the android source code.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
1087427
  • 465
  • 5
  • 18
0

Change your accept call method by this:

public static void acceptCall(Context context) 
{
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, 
      new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
} 
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Hitesh Singh
  • 1,951
  • 1
  • 10
  • 15
0

You need to create a broadcast receiver in which you will get the event when your phone is ringing and after that you can launch your desired activity.You can not replace the default incoming call screen until using CUSTOM ROM. And do not forget to set the priority in broadcast receiver in manifest file. Once you get the event you can use the object of ITelephony by using reflection.And that can provide you methods to answering or rejecting the call.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Deepak Goel
  • 5,624
  • 6
  • 39
  • 53