MMS發(fā)送流程代碼版android.doc_第1頁
MMS發(fā)送流程代碼版android.doc_第2頁
MMS發(fā)送流程代碼版android.doc_第3頁
MMS發(fā)送流程代碼版android.doc_第4頁
MMS發(fā)送流程代碼版android.doc_第5頁
已閱讀5頁,還剩25頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、MMS發(fā)送流程 ( 代碼版 )Android2.2packages/apps/Mms1. 點擊發(fā) 送按鈕 Src/com/android/mms/ui/ComposeMessageActivity.java public void onClick(View v) if (v = mSendButton) & isPreparedForSending() confirmSendMessageIfNeeded(); /確認(rèn)是否需要 發(fā)送短信- 2.src/com/android/mms/ui/ComposeMessageActivity.javaprivate void confirmSendMe

2、ssageIfNeeded() if (!isRecipientsEditorVisible() /編輯聯(lián) 系人不可 見時 ,也就是 給已存在會 話的聯(lián)系人發(fā)送短信 時sendMessage(true);return;boolean isMms = mWorkingMessage.requiresMms();/是否需要以彩信形式發(fā)送if (mRecipientsEditor.hasInvalidRecipient(isMms) /是否含有不合法的收件人if (mRecipientsEditor.hasValidRecipient(isMms) /有合法的和不合法的,彈出嘗試發(fā)送對話框Strin

3、g title = getResourcesString(R.string.has_invalid_recipient,mRecipientsEditor.formatInvalidNumbers(isMms);new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(title).setMessage(R.string.invalid_recipient_message).setPositiveButton(R.string.try_to_send,newSendIgnoreInval

4、idRecipientListener().setNegativeButton(R.string.no, new CancelSendingListener().show(); else /如果全是不合法的 聯(lián)系人,提示不能 發(fā)送信息 new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.cannot_send_message).setMessage(R.string.cannot_send_message_reason).setPositiveButton(R.s

5、tring.yes, new CancelSendingListener().show(); else /判斷收件人沒有問題,接著 發(fā)送信息 - sendMessage(true);3. src/com/android/mms/ui/ComposeMessageActivity.java private void sendMessage(boolean bCheckEcmMode) Log.v(TAG, sendMessage); if (bCheckEcmMode) / TODO: expose this in telephony layer for SDK buildString inEc

6、m =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 (Act

7、ivityNotFoundException e) / continue to send messageLog.e(TAG, Cannot find EmergencyCallbackModeExitDialog, e);if (!mSendingMessage) / send can change the recipients. Make sure we remove the listeners firstandthen add/ them back once the recipient list has settled.removeRecipientsListeners(); /取消對收件

8、人的 監(jiān)聽mWorkingMessage.send();/發(fā)送信息- mSentMessage = true;mSendingMessage = true;addRecipientsListeners(); /重新添加收件人監(jiān)聽/ But bail out if we are supposed to exit after the message is sent.if (mExitOnSent) /如果 mExitOnSent 為 true ,信息 發(fā)送完成后退出Activityfinish();4. src/com/android/mms/data/WorkingMessage.java/*

9、Send this message over the network. Will call back with onMessageSent() once* it has been dispatched to the telephonystack. This WorkingMessage object is* no longer useful after this method hasbeen called.*/public void send() if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) LogTag.debug(send);/ G

10、et ready to write to disk.prepareForSave(true /* notify */);/主要做一下同步收件人和WorkingMessage ,彩信 時在準(zhǔn)備其他一些 東西/ We need the recipient list for both SMS and MMS. final Conversation conv = mConversation;String msgTxt = mText.toString(); Log.v(TAG, msgText = + msgTxt);if (requiresMms()| addressContainsEmailToM

11、ms(conv, msgTxt) / Make local copies of the bits we need for sending a message,/ because we will be doing it off of the main thread, which will/ immediately continue on to resetting some of this state.final Uri mmsUri = mMessageUri;/如果第一次 發(fā)送,此 時 mmsUri 為 null ,如果是重發(fā),則是草稿箱的地址mMessageUri =content:/mms

12、/drafts/1final PduPersister persister = PduPersister.getPduPersister(mContext);final SlideshowModel slideshow = mSlideshow;final SendReq sendReq = makeSendReq(conv,mSubject);/ Do the dirty work of sending the message off of the main UI thread.new Thread(new Runnable() public void run() / Make sure t

13、he text in slide 0 is no longer holding onto areference to/ the text in the message text box. slideshow.prepareForSend();sendMmsWorker(conv, mmsUri, persister, slideshow, sendReq);).start();else / Same rules apply as above.final String msgText = mText.toString();/取出短消息Log.v(TAG, msgText = + msgText)

14、;new Thread(new Runnable() public void run() preSendSmsWorker(conv, msgText);/發(fā)送信息 - ).start();/ update the Recipient cache with the new to address, if its different RecipientIdCache.updateNumbers(conv.getThreadId(),conv.getRecipients();/ Mark the message as discarded because it is off the marketaft

15、er being sent. mDiscarded = true;5. src/com/android/mms/data/WorkingMessage.javaprivate void sendMmsWorker(Conversation conv, Uri mmsUri, PduPersisterpersister, SlideshowModel slideshow, SendReq sendReq) Log.v(TAG, sendMmsWorker);/ If user tries to send the message, its a signal the inputtedtext is

16、what theywanted.UserHappinessSignals.userAcceptedImeText(mContext);/ First make sure we dont have too many outstanding unsent message. Cursor cursor = null;try cursor = SqliteWrapper.query(mContext, mContentResolver,Mms.Outbox.CONTENT_URI,MMS_OUTBOX_PROJECTION, null, null, null);if (cursor != null)

17、/如果 MMS_OUTBOX里有未 發(fā)送的彩信,并且總的大小已 經(jīng)超過了彩信的最大限制,則取消此次 發(fā)送,并存入草稿箱Log.v(TAG, query Mms.Outbox.CONTENT_URI is not empty);long maxMessageSize = MmsConfig.getMaxSizeScaleForPendingMmsAllowed()*MmsConfig.getMaxMessageSize();Log.v(TAG, MmsConfig.getMaxSizeScaleForPendingMmsAllowed() = + MmsConfig.getMaxSizeScal

18、eForPendingMmsAllowed();Log.v(TAG, MmsConfig.getMaxMessageSize()() = + MmsConfig.getMaxMessageSize();long totalPendingSize = 0;while (cursor.moveToNext() totalPendingSize +=cursor.getLong(MMS_MESSAGE_SIZE_INDEX);Log.v(TAG, totalPendingSize = + totalPendingSize);if (totalPendingSize = maxMessageSize)

19、 unDiscard();/ itwasnt successfully sent. Allow it to be savedas a draft.mStatusListener.onMaxPendingMessagesReached();return;elseLog.v(TAG, query Mms.Outbox.CONTENT_URI is empty); finally if (cursor != null) cursor.close();mStatusListener.onPreMessageSent();/ Make sure we are still using the correc

20、t thread ID for our/ recipient set.long threadId = conv.ensureThreadId();if (Log.isLoggable(LogTag.APP, Log.VERBOSE) LogTag.debug(sendMmsWorker: update draft MMS message + mmsUri);if (mmsUri = null) /如果是首次 發(fā)送,先把彩信保存入草稿箱/ Create a new MMS message if one hasnt been made yet. Log.v(TAG, mmsUri = null a

21、nd startcreateDraftMmsMessage);mmsUri = createDraftMmsMessage(persister,sendReq, slideshow); else / Otherwise, sync the MMS message in progress to disk. Log.v(TAG, mmsUri = + mmsUri);Log.v(TAG, updateDraftMmsMessage);updateDraftMmsMessage(mmsUri,persister, slideshow, sendReq);/ Be paranoid and clean

22、 any draft SMS up. deleteDraftSmsMessage(threadId);/ Resize all the resizeable attachments (e.g. pictures) to fit/ in the remaining space in the error = 0;try slideshow.finalResize(mmsUri); catch (ExceedMessageSizeException e1) error = MESSAGE_SIZE_EXCEEDED; catch (MmsException e1) err

23、or = UNKNOWN_ERROR;if (error != 0) markMmsMessageWithError(mmsUri);mStatusListener.onAttachmentError(error);return;MessageSender sender = new MmsMessageSender(mContext, mmsUri,slideshow.getCurrentMessageSize();try if (!sender.sendMessage(threadId) / The message was sent through SMS protocol, we shou

24、ld/ delete the copy which was previously saved in MMS drafts. SqliteWrapper.delete(mContext, mContentResolver, mmsUri, null, null);/ Make sure this thread isnt over the limits in message count Recycler.getMmsRecycler().deleteOldMessagesByThreadId(mContext, threadId); catch (Exception e) Log.e(TAG, F

25、ailed to send message: + mmsUri + ,threadId= + threadId, e);mStatusListener.onMessageSent();6.src/com/android/mms/transaction/MmsMessageSender.javapublic boolean sendMessage(long token) throws MmsException / Load the MMS from the message uriPduPersister p = PduPersister.getPduPersister(mContext);Gen

26、ericPdu pdu = p.load(mMessageUri);if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_SEND_REQ)throw new MmsException(Invalid message: +pdu.getMessageType();SendReq sendReq = (SendReq)pdu;/ Update headers. updatePreferencesHeaders(sendReq);/ MessageClass.sendReq.setMessageClass(DEFAULT_MESSAGE_CLASS

27、.getBytes();/ Update the date field of the message before sending it. sendReq.setDate(System.currentTimeMillis()/ 1000L);sendReq.setMessageSize(mMessageSize);p.updateHeaders(mMessageUri, sendReq);/ Move the message into MMS Outbox p.move(mMessageUri, Mms.Outbox.CONTENT_URI);/ Start MMS transaction s

28、ervice SendingProgressTokenManager.put(ContentUris.parseId(mMessageUri), token); mContext.startService(new Intent(mContext, TransactionService.class);return true;7.src/com/android/mms/transaction/TransactionService.javaOverridepublic int onStartCommand(Intent intent, int flags, int startId) Log.v(TA

29、G, onStartCommand);if (intent = null) return Service.START_NOT_STICKY;mConnMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);boolean noNetwork =!isNetworkAvailable();if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, onStart: # + startId + : + intent.getExtras() +

30、 intent= +intent);Log.v(TAG, networkAvailable= + !noNetwork);Log.v(TAG, getAction is + intent.getAction();if (ACTION_ONALARM.equals(intent.getAction()| (intent.getExtras() = null) Log.v(TAG, ACTION_ONALARM.equals(intent.getAction() |(intent.getExtras() =null);/ Scan database to find all pending oper

31、ations.Cursor cursor = PduPersister.getPduPersister(this).getPendingMessages(System.currentTimeMillis();if (cursor != null) try int count = cursor.getCount();if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, onStart: cursor.count= + count);if (count = 0) if (Log.isLoggable(LogTag.TRANSA

32、CTION, Log.VERBOSE) Log.v(TAG, onStart: no pending messages.Stoppingservice.);RetryScheduler.setRetryAlarm(this);stopSelfIfIdle(startId);return Service.START_NOT_STICKY;int columnIndexOfMsgId=cursor.getColumnIndexOrThrow(PendingMessages.MSG_ID);int columnIndexOfMsgType =cursor.getColumnIndexOrThrow(

33、PendingMessages.MSG_TYPE);if (noNetwork) / Make sure we register for connection state changes.if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, onStart: registerForConnectionStateChanges);MmsSystemEventReceiver.registerForConnectionStateChanges(getApplicationContext();while (cursor.move

34、ToNext() int msgType =cursor.getInt(columnIndexOfMsgType);int transactionType =getTransactionType(msgType);Log.v(TAG, msgType = + msgType);Log.v(TAG, transactionType = + transactionType);if (noNetwork) onNetworkUnavailable(startId, transactionType);return Service.START_NOT_STICKY;switch (transaction

35、Type)case -1:break;case Transaction.RETRIEVE_TRANSACTION:/ If its a transiently failed transaction,/ we should retry it in spite of current/ downloading failureType =cursor.getInt(cursor.getColumnIndexOrThrow(PendingMessages.ERROR_TYPE);if (!isTransientFailure(failureType)break;/ fall-throu

36、ghdefault:Uri uri =ContentUris.withAppendedId(cursor.getLong(columnIndexOfMsgId);transactionType, uri.toString();/ FIXME: We use the same startId for all MMs. launchTransaction(startId, args, false); break; finally cursor.close(); else if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, o

37、nStart: no pending messages. Stoppingservice.);RetryScheduler.setRetryAlarm(this);stopSelfIfIdle(startId); else if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, onStart: launch transaction.);/ For launching NotificationTransaction and test purpose. TransactionBundle args = newTransacti

38、onBundle(intent.getExtras(); launchTransaction(startId, args,noNetwork);return Service.START_NOT_STICKY;8. src/com/android/mms/transaction/TransactionService.javaprivate void launchTransaction(int serviceId,TransactionBundle txnBundle, boolean noNetwork)Log.v(TAG, launchTransaction);if (noNetwork) L

39、og.w(TAG, launchTransaction: no network error!);onNetworkUnavailable(serviceId,txnBundle.getTransactionType();return;Message msg = mServiceHandler.obtainMessage(EVENT_TRANSACTION_REQUEST);msg.arg1 = serviceId;msg.obj = txnBundle;if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, launchTr

40、ansaction: sending message + msg);mServiceHandler.sendMessage(msg);9. src/com/android/mms/transaction/TransactionService.javaprivate final class ServiceHandler extends Handler public ServiceHandler(Looper looper) super(looper);/* Handle incoming transactionrequests.* The incoming requests are initia

41、tedby the MMSC Server or by the* MMS Client itself.*/Overridepublic void handleMessage(Messagemsg) if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, Handling incoming message: + msg);Transaction transaction = null;switch (msg.what) case EVENT_QUIT:getLooper().quit();return;case EVENT_CO

42、NTINUE_MMS_CONNECTIVITY:synchronized (mProcessing) if (mProcessing.isEmpty() return;if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, handle EVENT_CONTINUE_MMS_CONNECTIVITYevent.);try int result =beginMmsConnectivity();if (result != Phone.APN_ALREADY_ACTIVE)Log.v(TAG, Extending MMS conn

43、ectivity returned + result+ instead of APN_ALREADY_ACTIVE);/ Just wait for connectivity startup without/ any newrequest of APN switch.return; catch (IOException e) Log.w(TAG, Attempt to extend use of MMS connectivityfailed);return;/ Restart timersendMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CO

44、NNECTIVITY),APN_EXTENSION_WAIT);return;case EVENT_DATA_STATE_CHANGED:/* If we are being informedthat connectivity has been established* to allow MMS traffic,then proceed with processing the pending* transaction, if any.*/if (mConnectivityListener = null) return;NetworkInfo info = mConnectivityListen

45、er.getNetworkInfo();if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, Handle DATA_STATE_CHANGED event: + info);/ Check availability of the mobile network. if (info = null) | (info.getType() !=ConnectivityManager.TYPE_MOBILE_MMS) if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(

46、TAG, type isnot TYPE_MOBILE_MMS, bail);return;if (!info.isConnected() if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, TYPE_MOBILE_MMS not connected, bail);return;TransactionSettings settings = newTransactionSettings(TransactionService.this,info.getExtraInfo();/ If this APN doesnt have

47、 an MMSC, wait for one that does. if (TextUtils.isEmpty(settings.getMmscUrl()if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) Log.v(TAG, empty MMSCurl, bail);return;/ Set a timer to keep renewing our lease on the MMSconnection sendMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),APN_

48、EXTENSION_WAIT);processPendingTransaction(transaction, settings);return;case EVENT_TRANSACTION_REQUEST:/響應(yīng)請 求Log.v(TAG, EVENT_TRANSACTION_REQUEST);int serviceId = msg.arg1;try TransactionBundle args= (TransactionBundle) msg.obj;TransactionSettingstransactionSettings;/ Set the connection settings for this transaction./ If these have not been set in args, load thedefault settings. String mmsc =args.getMmscU

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論