Android短信开发 发送短信 ' 高通源码 '(发送成功或发送失败改变状态)
发布日期:2021-06-30 21:23:16 浏览次数:2 分类:技术文章

本文共 4077 字,大约阅读时间需要 13 分钟。

 

短信普通发送过程

在执行完 SmsSindleRecipientSender.java 类会重新开启广播 SmsReceiver.java重新启动服务SmsReceiverService.java

如果发送成功传入一个Action  "com.android.mms.transaction.MESSAGE_SENT"    ,

 

 

执行完SmsSindleRecipientSender.java类后执行SmsReceiverService.java里面handleSmsSend(Intent intent,int error)

private void handleSmsSent(Intent intent, int error) {//发送成功更改状态        Uri uri = intent.getData();        int resultCode = intent.getIntExtra("result", 0);//发送状态是否发送成功          boolean sendNextMsg = intent.getBooleanExtra(EXTRA_MESSAGE_SENT_SEND_NEXT, false);        int subId = intent.getIntExtra(ConstantsWrapper.Phone.SUBSCRIPTION_KEY,                SubscriptionManager.getDefaultSmsSubscriptionId());        mSending.put(subId, false);        LogTag.debugD("handleSmsSent uri: " + uri + " sendNextMsg: " + sendNextMsg +                " resultCode: " + resultCode +                " = " + translateResultCode(resultCode) + " error: " + error);        if (resultCode == Activity.RESULT_OK) {            if (sendNextMsg) {                Log.v(TAG, "handleSmsSent: move message to sent folder uri: " + uri);                if (!TelephonyWrapper.Sms.moveMessageToFolder(this, uri, Sms.MESSAGE_TYPE_SENT, error)) {                    Log.e(TAG, "handleSmsSent: failed to move message " + uri + " to sent folder");                }                sendFirstQueuedMessage(subId);            }            // Update the notification for failed messages since they may be deleted.            MessagingNotification.nonBlockingUpdateSendFailedNotification(this);        } else if ((resultCode == SmsManager.RESULT_ERROR_RADIO_OFF) ||  //发送失败                (resultCode == SmsManager.RESULT_ERROR_NO_SERVICE)) {            LogTag.debugD("handleSmsSent: no service, queuing message w/ uri: " + uri);            // We got an error with no service or no radio. Register for state changes so            // when the status of the connection/radio changes, we can try to send the            // queued up messages.            registerForServiceStateChanges();            // We couldn't send the message, put in the queue to retry later.            TelephonyWrapper.Sms.moveMessageToFolder(this, uri, Sms.MESSAGE_TYPE_QUEUED, error);            mToastHandler.post(new Runnable() {                public void run() {//拔卡发送  liwangjiang                    Toast.makeText(SmsReceiverService.this, getString(R.string.message_queued),                            Toast.LENGTH_SHORT).show();                    //拔卡时更改状态                    TelephonyWrapper.Sms.moveMessageToFolder(getApplicationContext(), uri, Sms.MESSAGE_TYPE_FAILED, error);//改变状态                }            });        } else if (resultCode == SmsManagerWrapper.RESULT_ERROR_FDN_CHECK_FAILURE) {            messageFailedToSend(uri, resultCode);            mToastHandler.post(new Runnable() {                public void run() {                    Toast.makeText(SmsReceiverService.this, getString(R.string.fdn_check_failure),                            Toast.LENGTH_SHORT).show();                }            });            if (sendNextMsg) {                sendFirstQueuedMessage(subId);            }        } else {            messageFailedToSend(uri, error);            if (sendNextMsg) {                sendFirstQueuedMessage(subId);  //关闭广播            }        }    }

 

 

改变状态的代码

TelephonyWrapper.Sms.moveMessageToFolder(getApplicationContext(), uri, Sms.MESSAGE_TYPE_FAILED, error);

发送状态

/** Message type: all messages. */        public static final int MESSAGE_TYPE_ALL    = 0;        /** Message type: inbox. */        public static final int MESSAGE_TYPE_INBOX  = 1;        /** Message type: sent messages. */        public static final int MESSAGE_TYPE_SENT   = 2;        /** Message type: drafts. */        public static final int MESSAGE_TYPE_DRAFT  = 3;        /** Message type: outbox. */        public static final int MESSAGE_TYPE_OUTBOX = 4;        /** Message type: failed outgoing message. */        public static final int MESSAGE_TYPE_FAILED = 5;        /** Message type: queued to send later. */        public static final int MESSAGE_TYPE_QUEUED = 6;

 

转载地址:https://liwangjiang.blog.csdn.net/article/details/88672620 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android短信开发 发送彩信 ‘ 高通源码 ‘ (彩信发送过程1)
下一篇:synchronized的作用

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月09日 15时16分32秒