是否可以打电话给某人,如果没人接听,则将呼叫下一个联系人?

问题描述

是否可以给某人打电话,而当没有人接听时,将呼叫下一个联系人? 我正在尝试编写这样的应用程序,我读了Build a calling app,但即使使用自定义UI进行常规调用也无法理解。我很沮丧。

解决方法

您需要获取电话通话状态,以下代码段将为您提供帮助。

PhoneStateChangeListener pscl = new PhoneStateChangeListener();
TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(pscl,PhoneStateListener.LISTEN_CALL_STATE);

在该状态之后,如果未应答,您可以在内部触发下一个呼叫。

有关更多电话状态侦听器,请查看here

下面的代码是使用常规方式缩进呼叫号码的示例。

Intent intent = new Intent(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);

别忘了添加通话权限

android.permission.CALL_PHONE