MMS发送流程(代码版)android

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

MMS发送流程(代码版)Android2.2packages/apps/Mms1.点击发送按钮Src/com/android/mms/ui/ComposeMessageActivity.javapublicvoidonClick(Viewv){if((v==mSendButton)&&isPreparedForSending()){confirmSendMessageIfNeeded();//确认是否需要发送短信—-》}}2.src/com/android/mms/ui/ComposeMessageActivity.javaprivatevoidconfirmSendMessageIfNeeded(){if(!isRecipientsEditorVisible()){//编辑联系人不可见时,也就是给已存在会话的联系人发送短信时sendMessage(true);return;}booleanisMms=mWorkingMessage.requiresMms();//是否需要以彩信形式发送if(mRecipientsEditor.hasInvalidRecipient(isMms)){//是否含有不合法的收件人if(mRecipientsEditor.hasValidRecipient(isMms)){//有合法的和不合法的,弹出尝试发送对话框Stringtitle=getResourcesString(R.string.has_invalid_recipient,mRecipientsEditor.formatInvalidNumbers(isMms));newAlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(title).setMessage(R.string.invalid_recipient_message).setPositiveButton(R.string.try_to_send,newSendIgnoreInvalidRecipientListener()).setNegativeButton(R.string.no,newCancelSendingListener()).show();}else{//如果全是不合法的联系人,提示不能发送信息newAlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.cannot_send_message).setMessage(R.string.cannot_send_message_reason).setPositiveButton(R.string.yes,newCancelSendingListener()).show();}}else{//判断收件人没有问题,接着发送信息--》sendMessage(true);}}3.src/com/android/mms/ui/ComposeMessageActivity.javaprivatevoidsendMessage(booleanbCheckEcmMode){Log.v(TAG,sendMessage);if(bCheckEcmMode){//TODO:exposethisintelephonylayerforSDKbuildStringinEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE);//判断电话是否处于紧急拨号模式,得到的inEcm一般为空Log.v(TAG,inEcm=+inEcm);if(Boolean.parseBoolean(inEcm)){try{startActivityForResult(newIntent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS,null),REQUEST_CODE_ECM_EXIT_DIALOG);return;}catch(ActivityNotFoundExceptione){//continuetosendmessageLog.e(TAG,CannotfindEmergencyCallbackModeExitDialog,e);}}}if(!mSendingMessage){//sendcanchangetherecipients.Makesureweremovethelistenersfirstandthenadd//thembackoncetherecipientlisthassettled.removeRecipientsListeners();//取消对收件人的监听mWorkingMessage.send();//发送信息—-》mSentMessage=true;mSendingMessage=true;addRecipientsListeners();//重新添加收件人监听}//Butbailoutifwearesupposedtoexitafterthemessageissent.if(mExitOnSent){//如果mExitOnSent为true,信息发送完成后退出Activityfinish();}}4.src/com/android/mms/data/WorkingMessage.java/***Sendthismessageoverthenetwork.WillcallbackwithonMessageSent()once*ithasbeendispatchedtothetelephonystack.ThisWorkingMessageobjectis*nolongerusefulafterthismethodhasbeencalled.*/publicvoidsend(){if(Log.isLoggable(LogTag.TRANSACTION,Log.VERBOSE)){LogTag.debug(send);}//Getreadytowritetodisk.prepareForSave(true/*notify*/);//主要做一下同步收件人和WorkingMessage,彩信时在准备其他一些东西//WeneedtherecipientlistforbothSMSandMMS.finalConversationconv=mConversation;StringmsgTxt=mText.toString();Log.v(TAG,msgText=+msgTxt);if(requiresMms()||addressContainsEmailToMms(conv,msgTxt)){//Makelocalcopiesofthebitsweneedforsendingamessage,//becausewewillbedoingitoffofthemainthread,whichwill//immediatelycontinueontoresettingsomeofthisstate.finalUrimmsUri=mMessageUri;//如果第一次发送,此时mmsUri为null,如果是重发,则是草稿箱的地址mMessageUri=content://mms/drafts/1finalPduPersisterpersister=PduPersister.getPduPersister(mContext);finalSlideshowModelslideshow=mSlideshow;finalSendReqsendReq=makeSendReq(conv,mSubject);//DothedirtyworkofsendingthemessageoffofthemainUIthread.newThread(newRunnable(){publicvoidrun(){//Makesurethetextinslide0isnolongerholdingontoareferenceto//thetextinthemessagetextbox.slideshow.prepareForSend();sendMmsWorker(conv,mmsUri,persister,slideshow,sendReq);}}).start();}else{//Samerulesapplyasabove.finalStringmsgText=mText.toString();//取出短消息Log.v(TAG,msgText=+msgText);newThread(newRunnable(){publicvoidrun(){preSendSmsWorker(conv,msgText);//发送信息--》}}).start();}//updatetheRecipientcachewiththenewtoaddress,ifit'sdifferentRecipientIdCache.updateNumbers(conv.getThreadId(),conv.getRecipients());//Markthemessageasdiscardedbecauseitisoffthemarketafterbeingsent.mDiscarded=true;}5.src/com/android/mms/data/WorkingMessage.javaprivatevoidsendMmsWorker(Conversationconv,UrimmsUri,PduPersisterpersister,SlideshowModelslideshow,SendReqsendReq){Log.v(TAG,sendMmsWorker);//Ifusertriestosendthemessage,it'sasignaltheinputtedtextiswhattheywanted.UserHappinessSignals.userAcceptedImeText(mContext);//Firstmakesurewedon'thavetoomanyoutstandingunsentmessage.Cursorcursor=null;try{cursor=SqliteWrapper.query(mContext,mContentResolver,Mms.Outbox.CONTENT_URI,MMS_OUTBOX_PROJECTION,null,null,null);if(cursor!=null){//如果MMS_OUTBOX里有未发送的彩信,并且总的大小已经超过了彩信的最大限制,则取消此次发送,并存入草稿箱Log.v(TAG,queryMms.Outbox.CONTENT_URIisnotempty);longmaxMessageSize=MmsConfig.getMaxSizeScaleForPendingMmsAllowed()*MmsConfig.getMaxMessageSize();Log.v(TAG,MmsConfig.getMaxSizeScaleForPendingMmsAllowed()=+MmsConfig.getMaxSizeScaleForPendingMmsAllowed());Log.v(TAG,MmsConfig.getMaxMessageSize()()=+MmsConfig.getMaxMessageSize());longtotalPendingSize=0;while(cursor.moveToNext()){totalPendingSize+=cursor.getLong(MMS_MESSAGE_SIZE_INDEX);Log.v(TAG,totalPendingSize=+totalP

1 / 30
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功