我已截获来电并在标准屏幕上显示我的活动。在此活动中,我有“接听电话”和“拒绝电话”按钮,但我无法正常工作。
我找到了两种以编程方式接听/拒绝电话的解决方案:
- 使用 ITelephony.aidl 但它仅在 api v10 之前有效。所以这是错误的方式
有以下内容:
private void acceptCall(Context context) { Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON); buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent( KeyEvent.ACTION_UP, 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"); } private void acceptCall(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"); }
从这里http://www.codeproject.com/Tips/578817/Reject-and-Accept-an-Incoming-Call
然而什么都没有!我单击按钮并相应地调用上面的方法,但没有任何反应。我在几个设备上测试了它,结果是一样的。
嗯,然后我在 samsung nexus one 上回答成功,但在 HTC 上回答不了。拒绝功能对两者都不起作用。