问题
What is current Phone state at the time of call end.
In android there are three states.
TelephonyManager.CALL_STATE_IDLE
TelephonyManager.CALL_STATE_OFFHOOK
TelephonyManager.CALL_STATE_RINGING:
回答1:
This code works for me. Hope it will help you
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;
}
}
回答2:
Once the call has ended the phone state should be TelephonyManager.CALL_STATE_IDLE
回答3:
Use PhoneStateListener to to receive notification of changes in specified telephony states.
Overide onCallStateChanged (int state, String incomingNumber)
and check the state
parameter
if (state == CALL_STATE_IDLE) {
//this is current Phone state at the time of call end, handle call end here
}
The three states indicate the following:
CALL_STATE_IDLE
-> Device call state: No activity.CALL_STATE_OFFHOOK
-> Device call state: Off-hook. At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.CALL_STATE_RINGING
-> Device call state: Ringing. A new call arrived and is ringing or waiting. In the latter case, another call is already active.
For more information, please refer the documentation.
回答4:
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)
来源:https://stackoverflow.com/questions/20257222/how-to-know-phone-call-has-ended