简体   繁体   English

如何以编程方式接听电话?

[英]How to programmatically answer a call?

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. 我发现了意图android.intent.action.ANSWER但似乎我获得的唯一效果是ActivityNotFoundException。 Why? 为什么? Is it a deprecated intent? 是否已弃用? How can I achieve answer? 如何获得答案? I have also heard about the "telnet technique". 我也听说过“ telnet技术”。 What is that? 那是什么?

Thanks 谢谢

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

不可能,请检查线程以获取更多信息。

It is possible to answer an Incoming Phone Call. 可以接听来电。 Check this out : here 检查一下: 这里

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. 这适用于Android 2.2到4.0,现在在将try catch添加到最后一行后,它适用于4.1.2和4.2。坦白地说,我不知道它的工作原理,但对我来说有效。

    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. 这对我在Android 4.1.2以及我在4.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. 模仿按键的行为。

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. 模拟BT手机所使用的方法不适用于所有Android版本和所有设备,因为BT手机的处理方式可能有所不同。

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: 在许多设备和Android版本中验证的最佳方法是模拟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 您也可以通过adb或通过Runtime.exec发送Shell命令“ input keyevent 5”来执行此操作,但就我而言,这不适用于所有设备

应答意图应发送到InCallScreen。

adb shell am start -n com.android.phone/.InCallScreen -a android.intent.action.ANSWER
try {
Runtime.getRuntime().exec("input keyevent"+Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
} catch (IOException e) {
   //handle error here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM