我想拨打一些电话号码,如果没有接听,请拨打另一个电话号码。
这可能吗?
我正在尝试使用此代码,但我始终先CALL_STATE_IDLE
和CALL_STATE_OFFHOOK
(仅在进行通话时),然后在完成通话时(因为通话不是)回答或因为它完成了)我再次CALL_STATE_IDLE
。
TelephonyManager manager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener callListener = new MyCallListener();
manager.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phoneNumber));
activity.startActivity(intent);
class MyCallListener extends PhoneStateListener
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
if (TelephonyManager.CALL_STATE_RINGING == state) {
Log.i(TAG, "RINGING, number: " + incomingNumber);
} else if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
Log.i(TAG, "OFFHOOK, number: " + incomingNumber);
} else if (TelephonyManager.CALL_STATE_IDLE == state) {
Log.i(TAG, "IDLE, number: " + incomingNumber);
} else {
Log.i(TAG, "Unexpected call state: " + state);
}
}
}
答案 0 :(得分:1)
您无法检测您的通话是否已被接听。
TelephonyManager.CALL_STATE_RINGING用于拨打电话而非拨出电话。
关注this
public static final int CALL_STATE_RINGING
Added in API level 1
Device call state: Ringing. A new call arrived and is ringing or waiting. In the latter case, another call is already active.
Constant Value: 1 (0x00000001)