1

着信を傍受し、標準画面にアクティビティを表示しました。このアクティビティには、「電話に出る」ボタンと「電話を拒否する」ボタンがありますが、機能しません。

プログラムで電話に応答/拒否するための2つの解決策を見つけました。

  1. ITelephony.aidl を使用しますが、API v10 より前でのみ機能します。だからやり方が間違ってる
  2. 次の場合:

    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 ではうまく答えられませんでした。拒否機能は両方で機能しません。

4

4 に答える 4

0

作成したアプリから電話をかけようとしたことを除いて、同様の問題がありました。これをマニフェストに追加することで修正されました。

 <uses-permission android:name="android.permission.CALL_PHONE" >
</uses-permission>
于 2013-10-31T15:14:07.513 に答える