着信を傍受し、標準画面にアクティビティを表示しました。このアクティビティには、「電話に出る」ボタンと「電話を拒否する」ボタンがありますが、機能しません。
プログラムで電話に応答/拒否するための2つの解決策を見つけました。
- 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 1 ではうまく答えられましたが、HTC ではうまく答えられませんでした。拒否機能は両方で機能しません。