7

I want to answer a phone call. I found the intent android.intent.action.ANSWER but it seems that the only effect that I obtain is an ActivityNotFoundException. Why? Is it a deprecated intent? How can I achieve answer? I have also heard about the "telnet technique". What is that?

Thanks

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Matroska
  • 6,885
  • 14
  • 63
  • 99

8 Answers8

6

you can also send call keyevent to answer calls but the device needs to be rooted

answer calls :

try {
    Thread.sleep(800); 
    Process process = Runtime.getRuntime().exec(new String[]{ "su","-c","input keyevent 5"});
    process.waitFor();

}catch (Exception e) {
    e.printStackTrace();
}

End calls :

try {
    Thread.sleep(800); 
    Process process = Runtime.getRuntime().exec(new String[]{ "su","-c","input keyevent 6"});
    process.waitFor();

}catch (Exception e) {
    e.printStackTrace();
}
Seifolahi
  • 919
  • 3
  • 11
  • 26
4

It's not possible, check this thread for further information.

systempuntoout
  • 71,966
  • 47
  • 171
  • 241
  • Ok, saw the thread...but why there is that intent? and it is not even deprecated! – Matroska Apr 09 '10 at 20:58
  • I know, if you google for ACTION_ANSWER, you would find many topics about people going crazy to find a way to autoanswer a call. This feature has surely been shut off by Android staff (security reason?). – systempuntoout Apr 10 '10 at 10:58
  • it is possiable check this app : https://play.google.com/store/apps/details?id=org.punkeroso.motoanswer&hl=en_IN&gl=US i have tested in android 11 it is working. – karan Sep 09 '21 at 08:06
3

It is possible to answer an Incoming Phone Call. Check this out : here

2

This works from Android 2.2 to 4.0 and now after adding the try catch to the last line it works for 4.1.2 and 4.2 Frankly speaking dont know how it works but it works for me.

    Log.d(tag, "InSecond Method Ans Call");
    // froyo and beyond trigger on buttonUp instead of buttonDown
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(
            KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");

    Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
    headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    headSetUnPluggedintent.putExtra("state", 0);
    headSetUnPluggedintent.putExtra("name", "Headset");
    try {
        sendOrderedBroadcast(headSetUnPluggedintent, null);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

This is working for me in Android 4.1.2 as well as i have tested on 4.2 This still gives an exception which is handled.

Maveňツ
  • 1
  • 12
  • 50
  • 89
PravinDodia
  • 3,271
  • 1
  • 18
  • 22
2

this event dose not work. you should use:

Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK);
i.putExtra(Intent.EXTRA_KEY_EVENT, event );
context.sendOrderedBroadcast(i, null);

that emulate a bhavior of press key.

razlebe
  • 7,134
  • 6
  • 42
  • 57
midoub
  • 21
  • 1
  • Does it actually work? I have not tried it yet. Did you? Thanks – Matroska Jun 03 '10 at 11:43
  • 1
    It works but then the speaker phone is muted. Any idea how to prevent this. I tried setMicrophoneMute(false) in the AudioManager class but no result?? – Bear Jun 22 '11 at 14:05
  • doesn't always work in Lollipop. Tried using it from a SERVICE, and will not work when coming from screen off status (when the call is made while phone is idle). – leRobot Apr 07 '15 at 14:40
1

The approach used by simulating a BT handset does not work with all Android Versions and with all Devices as BT handset handling may be different.

The best approach verified in lot of devices and Android versions consists in emulating the pressure and release of the Call button in the Dialer:

Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_CALL));
context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

// froyo and beyond trigger on buttonUp instead of buttonDown
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_CALL));
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED"); 

You can do that also by sending Shell command "input keyevent 5" via adb or via Runtime.exec but in my case wasn't working for all devices

Stephan
  • 41,764
  • 65
  • 238
  • 329
stefanogreg
  • 121
  • 1
  • 8
0

Answer intent should be sent to the InCallScreen.

adb shell am start -n com.android.phone/.InCallScreen -a android.intent.action.ANSWER
Nikhil
  • 16,194
  • 20
  • 64
  • 81
Rookie
  • 1
0
try {
Runtime.getRuntime().exec("input keyevent"+Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
} catch (IOException e) {
   //handle error here
}
Jana
  • 189
  • 1
  • 3
  • 13