Android6.0的SMS(短信)源码分析 | 您所在的位置:网站首页 › 长短信和普通短信的区别 › Android6.0的SMS(短信)源码分析 |
protected void handleSendComplete(AsyncResult ar) { SmsTracker tracker = (SmsTracker) ar.userObj;//从ar中解出tracker PendingIntent sentIntent = tracker.mSentIntent;//从tracker中解出sendIntent
if (ar.result != null) {//解出回应消息 tracker.mMessageRef = ((SmsResponse)ar.result).mMessageRef; } else { Rlog.d(TAG, "SmsResponse was null"); } if (ar.exception == null) {//如果没有异常,表示发送成功 if (DBG) Rlog.d(TAG, "SMS send complete. Broadcasting intent: " + sentIntent); //如果需要等待对方接受的结果状态,将tracker添加到pendinglist以等待结果 //需要注意的是这里的mSendItent和mDeliveryIntent都是pendingIntent,就是留待以后触发的意思,需要触发是调用PendingIntent.send()-—网络总结 if (tracker.mDeliveryIntent != null) { // Expecting a status report. Add it to the list. deliveryPendingList.add(tracker);//留待以后触发 } tracker.onSent(mContext);//发送消息广播,内部调用了PendingIntent.send() } else {//如果有异常,表示发送短信失败 if (DBG) Rlog.d(TAG, "SMS send failed"); //首先获取短信的状态 int ss = mPhone.getServiceState().getState(); //短信发送失败,可以重试,但服务不再Service状态,直接将重试次数设到超过最大 if ( tracker.mImsRetry > 0 && ss != ServiceState.STATE_IN_SERVICE) { // This is retry after failure over IMS but voice is not available. // Set retry to max allowed, so no retry is sent and // cause RESULT_ERROR_GENERIC_FAILURE to be returned to app. tracker.mRetryCount = MAX_SEND_RETRIES;//设置最大重试次数,即不重试
Rlog.d(TAG, "handleSendComplete: Skipping retry: " +" isIms()="+isIms() +" mRetryCount="+tracker.mRetryCount +" mImsRetry="+tracker.mImsRetry +" mMessageRef="+tracker.mMessageRef +" SS= "+mPhone.getServiceState().getState()); } // if sms over IMS is not supported on data and voice is not available... if (!isIms() && ss != ServiceState.STATE_IN_SERVICE) { tracker.onFailed(mContext, getNotInServiceError(ss), 0/*errorCode*/); } else if ((((CommandException)(ar.exception)).getCommandError() == CommandException.Error.SMS_FAIL_RETRY) && tracker.mRetryCount < MAX_SEND_RETRIES) { //发送失败,重试,从这里看出重试次数有次数限制 tracker.mRetryCount++; Message retryMsg = obtainMessage(EVENT_SEND_RETRY, tracker); sendMessageDelayed(retryMsg, SEND_RETRY_DELAY); } else { int errorCode = 0;//默认没有errorcode if (ar.result != null) {//根据ar设置errorcode errorCode = ((SmsResponse)ar.result).mErrorCode; } int error = RESULT_ERROR_GENERIC_FAILURE;//默认错误为这个 if (((CommandException)(ar.exception)).getCommandError() == CommandException.Error.FDN_CHECK_FAILURE) { //如果底层特殊上报了error,则根据底层设置error error = RESULT_ERROR_FDN_CHECK_FAILURE; } //将错误及错误code发送到上层,内部同样调用了PendingIntent.send()触发执行Intent tracker.onFailed(mContext, error, errorCode); } } } |
CopyRight 2018-2019 实验室设备网 版权所有 |