2010-04-09 104 views
7

我想接听电话。我找到了意图android.intent.action.ANSWER,但似乎我得到的唯一影响是一个ActivityNotFoundException。为什么?这是一个不赞成的意图吗?我如何获得答案?我也听说过“telnet技术”。那是什么?如何以编程方式接听电话?

感谢

回答

4

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

+0

好的,看到线程......但为什么有这种意图?它甚至不被弃用! – Matroska 2010-04-09 20:58:08

+0

我知道,如果你是谷歌的ACTION_ANSWER,你会发现很多关于人们为了找到一种自动打电话的方式而疯狂的话题。这个功能肯定已被Android员工关闭(安全原因?)。 – systempuntoout 2010-04-10 10:58:46

2

这个事件是不行的。 你应该使用:

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

是模拟按键的bhavior。

+0

它实际上工作吗?我还没有尝试过。你是否?谢谢 – Matroska 2010-06-03 11:43:27

+1

它的工作原理,但扬声器电话是静音的。任何想法如何防止这一点。我在AudioManager类中尝试setMicrophoneMute(false),但没有结果? – Bear 2011-06-22 14:05:42

+0

并不总是在棒棒糖中工作。尝试从服务中使用它,并且当从屏幕关闭状态(当电话空闲时进行呼叫)时不起作用。 – leRobot 2015-04-07 14:40:26

3

可以接听来电电话。看看这个:here

+1

这实际上是使用黑客技术,它可能会或可能不会在Android的下一次更新中发挥作用。 – 2013-06-25 20:28:02

0

应答意图应发送到InCallScreen。

adb shell am start -n com.android.phone/.InCallScreen -a android.intent.action.ANSWER 
6

你也可以将通话的KeyEvent来接听电话 但设备需要植根

接听电话:

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

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

挂断电话:

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

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

一个非常简单和简单的解决方案。为我工作。多谢了! – Basher51 2014-10-23 05:06:46

+0

这对于Android N来说已经不再可能了。https://source.android.com/security/bulletin/2016-03-01.html – AnixPasBesoin 2017-01-31 04:20:44

+0

看看日期。这是5年前:-) – Seifolahi 2017-01-31 06:15:09

1

的方法用于模拟BT手机不适用于所有Android版本和a由于BT手机处理可能会有所不同。

在很多设备和Android版本,包括在模拟的拨号器的压力和呼叫按钮的释放证明,最好的方法:

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"); 

你可以做到这一点还通过发送Shell命令“输入KeyEvent的5 “通过adb或通过Runtime.exec,但在我的情况下,并不适用于所有设备

2

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

这是Android 4.1.2为我工作,以及我对4.2 测试这仍然给它处理的异常。

0
try { 
Runtime.getRuntime().exec("input keyevent"+Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK)); 
} catch (IOException e) { 
    //handle error here 
} 
相关问题