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

标签 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);  
    }

最佳答案

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

When it is successfully delivered, it will display a "SMS delivered" message. Note that for testing using the emulator, when an SMS is successfully delivered, the "SMS delivered" message does not appear; this only works for real devices.

关于Android:在模拟器中未收到短信发送确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9503585/

相关文章:

javascript - Angular 确认框样式

python - OpennERP确认消息

javascript - HTML5 移动应用程序在手机屏幕关闭时运行?

android - 使用 MediaCodec 和 MediaExtractor 播放视频和音频

java - 为 7 位串联 SMS 创建 UDH

c++ - 如何从 C++ 代码与 GSM 调制解调器通信

php - 使用 PHP 检查 MySQLi 数据库中是否存在电子邮件

java - 如何从 Firestore 检索 Fragment 中的数据

java - 尝试将数据添加到数据库

ios - 用于 iPhone 的 HTML 文本链接向多个号码发送短信