【问题标题】:Android: Not receiving SMS delivered confirmation in emulatorAndroid:在模拟器中未收到短信发送的确认
【发布时间】:2012-02-29 17:14:08
【问题描述】:

我尝试做的是将短信发送到另一部手机并确认短信是否已送达。 现在,只有确认已发送短信有效。所以我收到消息说我的短信已发送,但我什么也没收到。 我正在使用 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);  
    }

【问题讨论】:

    标签: android sms confirmation


    【解决方案1】:

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

    发送成功后,会显示“短信已发送”消息。请注意,使用模拟器进行测试时,成功发送短信后,不会出现“短信已发送”消息;这仅适用于真实设备。

    【讨论】:

    • 多么可悲的buzinga!
    • 这就是为什么我引用了文章的相关部分,@joao2fast4u
    猜你喜欢
    • 2017-03-05
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多