I am attempting to create an application that will automatically answer calls when a checkbox is checked. I have added ITelephony.aidl to com.android.internal.telephony and have followed information on the web, but I can’t seem to get it going, it wont let me use the answerRingingCall(); method. error I am getting “telephonyService cannot be resolved” for telephonyService.answerRingingCall();
Any suggestions?
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();
}
}
});
}
}
You should call
telephonyService.answerRingingCall();method inPhoneStateListener