我正在尝试创建一个应用程序,该应用程序在选中复选框后会自动接听电话。我已经将ITelephony.aidl添加到com.android.internal.telephony中,并在网上关注了信息,但是我似乎无法理解,它不会让我使用answerRingingCall();方法。错误我为“ telephonyService.answerRingingCall();”获取“ telephonyService无法解析”

有什么建议么?

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;
import com.android.internal.telephony.ITelephony;

public class AnswerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        CheckBox AnswerCheckBox = (CheckBox) findViewById(R.id.answerCheck);

        AnswerCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {


            public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
            // TODO Auto-generated method stub
            if (buttonView.isChecked()) {

                telephonyService.answerRingingCall();


            Toast.makeText(getBaseContext(), "Calls will be answered",
            Toast.LENGTH_SHORT).show();
            }
            else
            {
            Toast.makeText(getBaseContext(), "Calls will NOT be answered",
            Toast.LENGTH_SHORT).show();
            }

            }
            });

            }

            }

最佳答案

您应该在telephonyService.answerRingingCall();中调用PhoneStateListener方法

  // Create a new PhoneStateListener
  listener = new PhoneStateListener() {
      @Override
      public void onCallStateChanged(int state, String incomingNumber) {

        switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:

          break;
        case TelephonyManager.CALL_STATE_OFFHOOK:

          break;
        case TelephonyManager.CALL_STATE_RINGING:
          // Ringing.. answer now
          telephonyService.answerRingingCall();
          break;
        }
   }

07-24 20:41