如何通过adb shell或keyevent接听来电

时间:2013-12-24 10:35:17

标签: android android-intent androidviewclient

我正在尝试使用Intent接听来电,如下所示:

device.shell("am start -n com.android.phone/.InCallScreen -a android.intent.action.ANSWER")        

任何人都可以告诉我哪里出错了...请帮忙。

3 个答案:

答案 0 :(得分:1)

device.press(“KEYCODE_CALL”,“DOWN”)

答案 1 :(得分:0)

答案 2 :(得分:0)

试试这个。它对我来说很好。

public static void answerCall(Context context) {

     Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);       
     buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
     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_HEADSETHOOK));
    context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");  
}