长短信发送

来源:互联网 发布:剪切视频在线软件 编辑:程序博客网 时间:2024/05/29 03:35

3,长短信发送

在上个章节的论述中, SmsManager的sendMultipartTextMessage方法中有关长短信的发送代码如下,

ISms iccISms = getISmsServiceOrThrow();if (iccISms != null) {      iccISms.sendMultipartTextForSubscriberWithOptions(getSubscriptionId(),          ActivityThread.currentPackageName(), destinationAddress, scAddress,          parts, sentIntents, deliveryIntents, priority, isExpectMore, validityPeriod);}

Isms就是phone进程的UiccSmsController服务,所以,最后调用的是phone进程的UiccSmsController的

sendMultipartTextForSubscriberWithOptions方法发送长短信,调用流程图如下,


sendMultipartTextForSubscriberWithOptions方法中直接调用IccSmsInterfaceManager的sendMultipartTextWithOptions方法,

主要逻辑如下,

1,首先进行权限检查,

mPhone.getContext().enforceCallingPermission(Manifest.permission.SEND_SMS,                "Sending SMS message");

2,然后调用ImsSMSDispatcher的sendMultipartText方法,

mDispatcher.sendMultipartText(destAddr, scAddr, (ArrayList<String>) parts,   (ArrayList<PendingIntent>) sentIntents, (ArrayList<PendingIntent>) deliveryIntents,   null, callingPackage, false /*persistMessage*/, priority, isExpectMore, validityPeriod);

在sendMultipartText方法中,根据网络制式选择调用不同Dispatcher对象的sendMultipartText方法,

if (isCdmaMo()) {    mCdmaDispatcher.sendMultipartText(destAddr, scAddr, parts, sentIntents, deliveryIntents, messageUri, callingPkg, persistMessage, priority, isExpectMore, validityPeriod);} else {     mGsmDispatcher.sendMultipartText(destAddr, scAddr, parts, sentIntents, deliveryIntents, messageUri, callingPkg, persistMessage, priority, isExpectMore, validityPeriod);}

如果是CDMA网络,就调用CdmaSMSDispatcher的sendMultipartText方法进行发送;

如果是GSM网络,就调用GsmSMSDispatcher的sendMultipartText方法进行发送;

其实都是在父类SMSDispatcher实现的, sendMultipartText方法如下,

1, 将拆分出来的短信分别加上短信头编码,也就是SmsHeader,

for (int i = 0; i < msgCount; i++) {    SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef();    concatRef.refNumber = refNumber;    concatRef.seqNumber = i + 1;  // 1-based sequenceconcatRef.msgCount = msgCount;•••concatRef.isEightBits = true;SmsHeader smsHeader = new SmsHeader();smsHeader.concatRef = concatRef;•••

2,分别调用sendSubmitPdu方法发送出去,

for (SmsTracker tracker : trackers) {   if (tracker != null) {       sendSubmitPdu(tracker);•••

GsmSMSDispatcher的sendSubmitPdu方法如下,

protected void sendSubmitPdu(SmsTracker tracker) {    sendRawPdu(tracker);}

直接调用sendRawPdu方法进行发送,这个方法以后的代码和发送普通短信完全相同。

由此可见,所谓的长短信发送就是将短信进行拆分,然后将拆分的短信像普通短信那样发送出去。

原创粉丝点击