【问题标题】:How to programmatically answer a call?如何以编程方式接听电话?
【发布时间】:2010-04-09 20:10:33
【问题描述】:

我想接听电话。我找到了意图android.intent.action.ANSWER,但似乎我获得的唯一效果是 ActivityNotFoundException。为什么?这是一个已弃用的意图吗?我怎样才能得到答案?我也听说过“telnet 技术”。那是什么?

谢谢

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    您也可以发送 call keyevent 来接听电话 但是设备需要root

    接听电话:

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

    【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 好的,看到了线程......但是为什么会有这种意图?它甚至没有被弃用!
    • 我知道,如果您在 Google 上搜索 ACTION_ANSWER,您会发现很多关于人们疯狂寻找自动接听电话的方法的话题。 Android 工作人员肯定已关闭此功能(出于安全原因?)。
    • 可以检查这个应用程序:play.google.com/store/apps/… 我已经在 android 11 中测试过它正在工作。
    【解决方案3】:

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

    【讨论】:

    • 这实际上是在使用 hack,它可能会或可能不会在 Android 的下一次更新中起作用。
    【解决方案4】:

    此事件不起作用。 你应该使用:

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

    模仿按键的行为。

    【讨论】:

    • 它真的有效吗?我还没有尝试过。你是否?谢谢
    • 它可以工作,但随后扬声器电话静音。任何想法如何防止这种情况。我在 AudioManager 类中尝试了 setMicrophoneMute(false) 但没有结果??
    • 在 Lollipop 中并不总是有效。尝试从 SERVICE 中使用它,但在屏幕关闭状态下(当手机空闲时拨打电话时)将无法正常工作。
    【解决方案5】:

    这适用于 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 上测试过 这仍然会给出一个已处理的异常。

    【讨论】:

      【解决方案6】:

      用于模拟 BT 手机的方法不适用于所有 Android 版本和所有设备,因为 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"); 
      

      您也可以通过 adb 或 Runtime.exec 发送 Shell 命令“input keyevent 5”来做到这一点,但在我的情况下,它不适用于所有设备

      【讨论】:

        【解决方案7】:

        应将应答意图发送到 InCallScreen。

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

        【讨论】:

          【解决方案8】:
          try {
          Runtime.getRuntime().exec("input keyevent"+Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
          } catch (IOException e) {
             //handle error here
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-02-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多