我假设启动了ACTION_ANSWER意图,但除此之外,在此之前或之后发生了什么我不知道。
有人能帮忙吗?
我假设启动了ACTION_ANSWER意图,但除此之外,在此之前或之后发生了什么我不知道。
有人能帮忙吗?
case CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:
log("RINGING... (new)");
onNewRingingConnection((AsyncResult) msg.obj);
mSilentRingerRequested = false;
break;
onNewRingingConnection(AsyncResult)
最终(在一般情况下)调用ringAndNotifyOfIncomingCall(Connection c)
:
private void ringAndNotifyOfIncomingCall(Connection c) {
if (PhoneUtils.isRealIncomingCall(c.getState())) {
mRinger.ring();
} else {
if (VDBG) log("- starting call waiting tone...");
if (mCallWaitingTonePlayer == null) {
mCallWaitingTonePlayer = new InCallTonePlayer(
InCallTonePlayer.TONE_CALL_WAITING);
mCallWaitingTonePlayer.start();
}
}
// CallModeler.onNewRingingConnection(Connection)
mCallModeler.onNewRingingConnection(c);
}
CallModeler.onNewRingingConnection(Connection)
(链接) 通知已附加的监听器:
for (int i = 0; i < mListeners.size(); ++i) {
mListeners.get(i).onIncoming(call);
}
CallModeler.Listener
接口。CallHandlerServiceProxy是其中之一的监听器,它的onIncoming(Call)
回调触发CallHandlerServiceProxy.processIncoming(Call)
:private void processIncoming(Call call) {
....
// ICallHandlerService
mCallHandlerServiceGuarded.onIncoming(call,
RejectWithTextMessageManager.loadCannedResponses());
....
}
CallHandlerService定义了一个ICallHandlerService.Stub
成员,并且它的onIncoming(Call, List<String>)
方法如下:
@Override
public void onIncoming(Call call, List<String> textResponses) {
....
mMainHandler.sendMessage(mMainHandler.obtainMessage(
ON_UPDATE_CALL_WITH_TEXT_RESPONSES, incomingCall));
....
}
mMainHandler
处理 ON_UPDATE_CALL_WITH_TEXT_RESPONSES
情况的方式:case ON_UPDATE_CALL_WITH_TEXT_RESPONSES:
AbstractMap.SimpleEntry<Call, List<String>> entry
= (AbstractMap.SimpleEntry<Call, List<String>>) msg.obj;
Log.i(TAG, "ON_INCOMING_CALL: " + entry.getKey());
// CallList
mCallList.onIncoming(entry.getKey(), entry.getValue());
break;
CallList维护一个实现CallList.Listener
接口的监听器列表,并从其CallList.onIncoming(Call, List<String>)
方法中触发他们的onIncomingCall(Call)
事件。
现在,让我们看看InCallPresenter:
/** * 接收来自CallList的更新并通知InCallActivity(UI)进行更改。 * 负责启动新呼叫的Activity并在所有呼叫断开连接时完成该Activity。 * 创建和管理呼叫状态并为想要侦听呼叫状态更改的Presenter提供侦听器模式。 * TODO:此类现在已成为状态机。请考虑重命名。 */
InCallPresenter
实现了CallList.Listener
接口,负责启动提供所有电话相关操作的UI的InCallActivity
。以下注释(取自InCallPresenter.startOrFinishUi(InCallState)
)将上述一系列事件联系在了一起:
/* A new Incoming call means that the user needs to be notified of the
the call (since it wasn't them who initiated it). We do this
through full screen notifications and happens indirectly through {@link
StatusBarListener}. The process for incoming calls is as follows:
1) CallList - Announces existence of new INCOMING call
2) InCallPresenter - Gets announcement and calculates that the new
InCallState should be set to INCOMING.
3) InCallPresenter - This method is called to see if we need to
start or finish the app given the new state.
4) StatusBarNotifier - Listens to InCallState changes. InCallPresenter
calls StatusBarNotifier explicitly to issue a
FullScreen Notification that will either start the
InCallActivity or show the user a top-level
notification dialog if the user is in
an immersive app. That notification can also start
the InCallActivity.
5) InCallActivity - Main activity starts up and at the end of its
onCreate will call InCallPresenter::setActivity()
to let the presenter know that start-up is complete.
[ AND NOW YOU'RE IN THE CALL. voila! ] */
我希望这回答了你的问题,或者至少给你指明了方向。如果我有遗漏或误解,请随时纠正。
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
//Not in call: Play music
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//A call is dialing, active or on hold
break;
case TelephonyManager.CALL_STATE_RINGING:
//Incoming call: Pause music
break;
}
}
谷歌参考文档为
http://developer.android.com/reference/android/telephony/TelephonyManager.html
请看这个 Grep code InCallScreen.java
else if (action.equals(Intent.ACTION_ANSWER)) {
internalAnswerCall();
app.setRestoreMuteOnInCallResume(false);
return InCallInitStatus.SUCCESS;