如何检查短信是否确实发送到了收件人的手机上?

时间:2018-10-30 19:53:50

标签: android sms send android-pendingintent smsmanager

我想检查短信是否真的发送到了收件人的手机上。

到目前为止,我发现的所有示例都显示了“已发送短信”,即使收件人的电话已关闭。因此,我感谢任何想法和代码段。

这是我当前正在使用的代码:

PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0, new 
Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(mContext, 0,new 
Intent(DELIVERED), 0);
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";


// ---when the SMS has been sent---

    mContext.registerReceiver(
            new BroadcastReceiver()
            {    
                @Override
                public void onReceive(Context arg0,Intent arg1)
                {
                    switch(getResultCode())
                    {
                     case Activity.RESULT_OK:
                     break;
                     case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                     break;
                     case SmsManager.RESULT_ERROR_NO_SERVICE:
                     break;
                     case SmsManager.RESULT_ERROR_NULL_PDU:
                     break;
                     case SmsManager.RESULT_ERROR_RADIO_OFF:
                     break;
                    }
                }
            }, new IntentFilter(SENT));


    // ---when the SMS has been delivered---

    mContext.registerReceiver(
            new BroadcastReceiver()
            {

                @Override
                public void onReceive(Context arg0,Intent arg1)
                {
                    switch(getResultCode())
                    {
                     case Activity.RESULT_OK:
                     break;
                     case Activity.RESULT_CANCELED:
                     break;
                    }
                }
            }, new IntentFilter(DELIVERED));


SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null,message,sentPI, deliveredPI);

0 个答案:

没有答案