Android:未在模拟器中接收短信已发送确认

时间:2012-02-29 17:14:08

标签: android sms confirmation

我尝试做的是将短信发送到另一部手机并在短信发送时获得确认。 现在,只确认已发送短信有效。所以我收到消息说我的短信已被发送,但后来我什么都没得到。 我正在使用2个模拟器来测试它,但我不认为这是问题所在。不幸的是,我暂时没有手机和手机:(

我的代码如下所示:

private void sendSms(String txt, String phone){
        PendingIntent sentPI = PendingIntent.getBroadcast(act, 0, new Intent(SENT), 0);
        PendingIntent deliveredPI = PendingIntent.getBroadcast(act, 0, new Intent(DELIVERED), 0);

      //---when the SMS has been sent---
        act.registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(act, "SMS sent", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(act, "Generic failure", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(act, "No service", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(act, "Null PDU", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(act, "Radio off", 
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        }, new IntentFilter(SENT));

        //---when the SMS has been delivered---
        act.registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {               
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(act, "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(act, "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phone, null, txt, sentPI, deliveredPI);  
    }

1 个答案:

答案 0 :(得分:6)

根据"SMS Messaging in Android"-tutorial on mobiforge.com,投放状态报告不适用于模拟器:

  

成功交付后,会显示"已发送短信"信息。请注意,对于使用模拟器进行测试,当成功传送SMS时," SMS已发送"消息没有出现;这仅适用于真实设备。