1

我正在尝试创建一个应用程序,该应用程序将在选中复选框时自动接听电话。我已将 ITelephony.aidl 添加到 com.android.internal.telephony 并关注网络上的信息,但我似乎无法继续,它不会让我使用该answerRingingCall();方法。错误我得到“无法解决电话服务”telephonyService.answerRingingCall();

有什么建议么?

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(); 
            } 

            } 
            }); 

            } 

            } 
4

2 回答 2

0

你应该调用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;
        }
   }
于 2012-05-20T07:00:57.847 回答
0

尝试查看answerPhoneAidl以下链接的方法: https ://code.google.com/p/auto-answer/source/browse/trunk/src/com/everysoft/autoanswer/AutoAnswerIntentService.java

于 2013-05-15T07:35:37.373 回答