【发布时间】:2010-04-09 20:10:33
【问题描述】:
我想接听电话。我找到了意图android.intent.action.ANSWER,但似乎我获得的唯一效果是 ActivityNotFoundException。为什么?这是一个已弃用的意图吗?我怎样才能得到答案?我也听说过“telnet 技术”。那是什么?
谢谢
【问题讨论】:
我想接听电话。我找到了意图android.intent.action.ANSWER,但似乎我获得的唯一效果是 ActivityNotFoundException。为什么?这是一个已弃用的意图吗?我怎样才能得到答案?我也听说过“telnet 技术”。那是什么?
谢谢
【问题讨论】:
您也可以发送 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();
}
【讨论】:
这是不可能的,请查看this 线程以获取更多信息。
【讨论】:
可以接听来电。看看这个:here
【讨论】:
此事件不起作用。 你应该使用:
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);
模仿按键的行为。
【讨论】:
这适用于 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 上测试过 这仍然会给出一个已处理的异常。
【讨论】:
用于模拟 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”来做到这一点,但在我的情况下,它不适用于所有设备
【讨论】:
应将应答意图发送到 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
}
【讨论】: