版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35427437/article/details/88672620
短信普通发送过程
https://blog.csdn.net/qq_35427437/article/details/88537120
在执行完 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;