Android 拨打电话流程

时间:2022-11-10 00:26:08

1、Contacts的AndroidManifest.xml中

   

PeopleActivity的intent-filter的action设置为main,catelog设置为launcher,此activity是点击此应用第一个界面。dialtactsactivity包含四个tab,分别由TwelveKeyDialer、RecentCallsListActivity,两个activity-aliasDialtactsContactsEntryActivity和DialtactsFavoritesEntryActivity分别表示联系人和收藏tab,但是正真的联系人列表和收藏是由ContactsListActivity负责。

        <!-- The main Contacts activity with the contact list, favorites, and groups. -->
<activity android:name=".activities.PeopleActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>


   
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);

createViewsAndFragments(savedState);//创建布局
}

    private void createViewsAndFragments(Bundle savedState) {
        // Disable the ActionBar so that we can use a Toolbar. This needs to be called before
        // setContentView().
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.people_activity);//布局文件

 ...
    }

 

MMIDialogActivity.java

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    switch (msg.what) {
                        case PhoneGlobals.MMI_COMPLETE:
                            Log.d(TAG, "handle MMI_COMPLETE");
                            onMMIComplete((AsyncResult) msg.obj);
                            break;
                    }
                }
        };
        mPhone.registerForMmiComplete(mHandler, PhoneGlobals.MMI_COMPLETE, null);
    }



    /**
     * Handles an MMI_COMPLETE event, which is triggered by telephony
     */
    private void onMMIComplete(AsyncResult r) {
        // Check the code to see if the request is ready to
        // finish, this includes any MMI state that is not
        // PENDING.
        MmiCode mmiCode = (MmiCode) r.result;
        String ussdHandler = null;
        if((r.userObj != null) && (r.userObj instanceof String)){
            ussdHandler = (String)r.userObj;
        }
        // if phone is a CDMA phone display feature code completed message
        int phoneType = mPhone.getPhoneType();
        if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
            PhoneUtils.displayMMIComplete(mPhone, this, mmiCode, null, null);//->
        }
    }



 
<pre name="code" class="java">PhoneGlobals.java    

oncreate() {
           // register for MMI/USSD
            mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);

 }

    private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
 if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
                int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);
                int phoneId = SubscriptionManager.getPhoneId(subId);
                String state = intent.getStringExtra(PhoneConstants.STATE_KEY);

                Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
                        PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
                // The "data disconnected due to roaming" notification is shown
                // if (a) you have the "data roaming" feature turned off, and
                // (b) you just lost data connectivity because you're roaming.
                boolean disconnectedDueToRoaming =
                        !phone.getDataRoamingEnabled()
                        && PhoneConstants.DataState.DISCONNECTED.equals(state)
                        && Phone.REASON_ROAMING_ON.equals(
                            intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
                if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
                    mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
                    mHandler.sendEmptyMessage(disconnectedDueToRoaming
                            ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
                }
           

}

               case MMI_COMPLETE:
                    onMMIComplete((AsyncResult) msg.obj);
                    break;


private void onMMIComplete(AsyncResult r) { if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); MmiCode mmiCode = (MmiCode) r.result; final Message message = Message.obtain(mHandler, MMI_CANCEL); PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, message, null); }

 



2、packages/services/Telephony/src/com/android/phone/PhoneUtils.java

    /**
* Handle the MMIComplete message and fire off an intent to display
* the message.
*
* @param context context to get strings.
* @param mmiCode MMI result.
* @param previousAlert a previous alert used in this activity.
*/
public static void displayMMIComplete(final Phone phone, Context context, final MmiCode mmiCode,
Message dismissCallbackMessage,
AlertDialog previousAlert)

        MmiCode.State state = mmiCode.getState();
        switch (state) {
            case FAILED:
                text = mmiCode.getMessage();

        }