如何查找是否已在android中回答了该呼叫

时间:2014-04-01 04:21:24

标签: android

我想仅在拨出电话时启动计时器。与Nexus 5中的默认手机应用程序一样。

有没有办法确定是否已接听电话?

在拨打电话号码后我立即尝试了电话听众,然后转到CALL_STATE_OFFHOOK。那么这不是正确的方法吗?

有人可以帮我解决这个问题吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

这个可以帮助你:

public class CallLogReceiver extends BroadcastReceiver {

static boolean missedCall, incomingCall;

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub


    if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
        String state = intent.getExtras().getString(
                TelephonyManager.EXTRA_STATE);

        if ((state != null)
                && (state.equals(TelephonyManager.EXTRA_STATE_RINGING))) {
            CallLogReceiver.phoneNo = intent.getExtras().getString(
                    "incoming_number");
            CallLogReceiver.missedCall = true;
        }

        if ((state != null)
                && (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))) {
            CallLogReceiver.incomingCall = true;

        }
        if (state != null
                && !(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
                && !(state.equals(TelephonyManager.EXTRA_STATE_RINGING))) {

            if (CallLogReceiver.missedCall && CallLogReceiver.incomingCall) {
                //incoming call logic
            }

            else if (CallLogReceiver.missedCall
                    && !CallLogReceiver.incomingCall) {
                // missed call logic
            }
            CallLogReceiver.missedCall = CallLogReceiver.incomingCall = false;
        }
      }
    }
}