gpt4 book ai didi

java - "telephonyService cannot be resolved"方法调用出现错误 `telephonyService.answerRingingCall();`

转载 作者:行者123 更新时间:2023-12-01 05:19:20 25 4
gpt4 key购买 nike

我正在尝试创建一个应用程序,该应用程序将在选中复选框时自动应答调用。我已将 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();
}

}
});

}

}

最佳答案

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

  // 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;
}
}

关于java - "telephonyService cannot be resolved"方法调用出现错误 `telephonyService.answerRingingCall();`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10671402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com