怎么知道电话会在android中结束

时间:2013-11-28 03:31:39

标签: android telephonymanager

通话结束时当前的电话状态是什么。

在android中有三种状态。

TelephonyManager.CALL_STATE_IDLE
TelephonyManager.CALL_STATE_OFFHOOK
TelephonyManager.CALL_STATE_RINGING:

4 个答案:

答案 0 :(得分:0)

通话结束后,手机状态应为TelephonyManager.CALL_STATE_IDLE

答案 1 :(得分:0)

使用PhoneStateListener接收指定电话状态更改的通知。

覆盖onCallStateChanged (int state, String incomingNumber)并检查state参数

if (state == CALL_STATE_IDLE) {  
    //this is current Phone state at the time of call end, handle call end here
}

这三个州表明如下:

  

CALL_STATE_IDLE - >设备呼叫状态:无活动    CALL_STATE_OFFHOOK    - >设备呼叫状态:摘机。至少存在一个拨号,活动或保持的呼叫,并且没有呼叫振铃或等待   CALL_STATE_RINGING - >设备呼叫状态:振铃。一个新的电话到了   正在响个不停。在后一种情况下,已经有另一个电话   活性

有关详细信息,请参阅documentation

答案 2 :(得分:0)

此代码适用于我。希望它能帮到你

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallStateReceiver extends BroadcastReceiver {

private final String LOG_TAG = "CallStateReceiver";

public static String prevState = TelephonyManager.EXTRA_STATE_IDLE;

@Override
public void onReceive(Context context, Intent intent) {

    Bundle bundle = intent.getExtras();
    if (bundle == null) {
        return;
    }

    String state = bundle.getString(TelephonyManager.EXTRA_STATE);

    if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)
            && !prevState.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)) {

        Log.i(this.LOG_TAG, "Call ended"));
    }

    prevState = state;
}
}

答案 3 :(得分:0)

TelephonyManager.CALL_STATE_IDLE    #When a call end, no matter what, call received by user or not

TelephonyManager.CALL_STATE_OFFHOOK #when user receive a call

TelephonyManager.CALL_STATE_RINGING #when phone ring (incoming call)