电话相关


1.来电流程分析

PhoneApp在初始化时会实例CallNotifier对象,Callnotifier主要是对电话状态的监听,通知事件


PhoneApp创建一个CallNotifier        
 
    // Create the CallNotifer singleton, which handles  
            // asynchronous events from the telephony layer (like  
            // launching the incoming-call UI when an incoming call comes  
            // in.)  
            notifier = CallNotifier.init(this, phone, ringer, mBtHandsfree, new CallLogAsync()); 

PhoneApp创建一个CallNotifier      

    // Create the CallNotifer singleton, which handles
            // asynchronous events from the telephony layer (like
            // launching the incoming-call UI when an incoming call comes
            // in.)
            notifier = CallNotifier.init(this, phone, ringer, mBtHandsfree, new CallLogAsync());
Callnotifier实现对电话状态的监听


/** Private constructor; @see init() */ 
 private CallNotifier(PhoneApp app, Phone phone, Ringer ringer, 
                      BluetoothHandsfree btMgr, CallLogAsync callLog) { 
     mApplication = app; 
     mCM = app.mCM; 
     mCallLog = callLog; 
 
     mAudioManager = (AudioManager) mApplication.getSystemService(Context.AUDIO_SERVICE); 
 
     <SPAN style="FONT-SIZE: 18px; COLOR: #cc0000"><STRONG>registerForNotifications();//状态监听</STRONG></SPAN> 

   /** Private constructor; @see init() */
    private CallNotifier(PhoneApp app, Phone phone, Ringer ringer,
                         BluetoothHandsfree btMgr, CallLogAsync callLog) {
        mApplication = app;
        mCM = app.mCM;
        mCallLog = callLog;

        mAudioManager = (AudioManager) mApplication.getSystemService(Context.AUDIO_SERVICE);

        registerForNotifications();//状态监听
 registerForNotifications方法注册电话状态监听


private void registerForNotifications() { 

    private void registerForNotifications() {
view plaincopyprint?mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null); 

        mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null);[java] view plaincopyprint?    mCM.registerForPreciseCallStateChanged(this, PHONE_STATE_CHANGED, null); 
    mCM.registerForDisconnect(this, PHONE_DISCONNECT, null); 
    mCM.registerForUnknownConnection(this, PHONE_UNKNOWN_CONNECTION_APPEARED, null); 
    mCM.registerForIncomingRing(this, PHONE_INCOMING_RING, null); 
    mCM.registerForCdmaOtaStatusChange(this, EVENT_OTA_PROVISION_CHANGE, null); 
    mCM.registerForCallWaiting(this, PHONE_CDMA_CALL_WAITING, null); 
    mCM.registerForDisplayInfo(this, PHONE_STATE_DISPLAYINFO, null); 
    mCM.registerForSignalInfo(this, PHONE_STATE_SIGNALINFO, null); 
    mCM.registerForInCallVoicePrivacyOn(this, PHONE_ENHANCED_VP_ON, null); 
    mCM.registerForInCallVoicePrivacyOff(this, PHONE_ENHANCED_VP_OFF, null); 
    mCM.registerForRingbackTone(this, PHONE_RINGBACK_TONE, null); 
    mCM.registerForResendIncallMute(this, PHONE_RESEND_MUTE, null); 

        mCM.registerForPreciseCallStateChanged(this, PHONE_STATE_CHANGED, null);
        mCM.registerForDisconnect(this, PHONE_DISCONNECT, null);
        mCM.registerForUnknownConnection(this, PHONE_UNKNOWN_CONNECTION_APPEARED, null);
        mCM.registerForIncomingRing(this, PHONE_INCOMING_RING, null);
        mCM.registerForCdmaOtaStatusChange(this, EVENT_OTA_PROVISION_CHANGE, null);
        mCM.registerForCallWaiting(this, PHONE_CDMA_CALL_WAITING, null);
        mCM.registerForDisplayInfo(this, PHONE_STATE_DISPLAYINFO, null);
        mCM.registerForSignalInfo(this, PHONE_STATE_SIGNALINFO, null);
        mCM.registerForInCallVoicePrivacyOn(this, PHONE_ENHANCED_VP_ON, null);
        mCM.registerForInCallVoicePrivacyOff(this, PHONE_ENHANCED_VP_OFF, null);
        mCM.registerForRingbackTone(this, PHONE_RINGBACK_TONE, null);
        mCM.registerForResendIncallMute(this, PHONE_RESEND_MUTE, null);
    }
  mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null); 监听来电,在handleMessage函数内处理


@Override 
   public void handleMessage(Message msg) { 
       switch (msg.what) { 
           case PHONE_NEW_RINGING_CONNECTION: 
               log("RINGING... (new)"); 
               onNewRingingConnection((AsyncResult) msg.obj); 
               mSilentRingerRequested = false; 
               break; 

 @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case PHONE_NEW_RINGING_CONNECTION:
                log("RINGING... (new)");
                onNewRingingConnection((AsyncResult) msg.obj);
                mSilentRingerRequested = false;
                break;转到onNewRingingConnection处理来电,最后转到showIncomingCall函数启动InCallScreen界面,当然还有处理一些状态更新,响铃之类的


2.拨号流程分析

拨号主要是从拨号盘按下call按键开始,进入OutgoingCallBroadcaster处理,




3.电话状态判断

private boolean isIdle(){
            boolean isIdle = false;
            TelephonyManager tm = (TelephonyManager) getSystemService("phone");
            if(tm != null){
                isIdle = (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE);
            }
            return isIdle;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值