2012-02-29 38 views
3

我尝试做的是发送短信到另一部手机,并得到确认,如果短信发送与否。 现在,只有确认短信已发送的作品。所以我得到的消息是,我的短信已发送,但我什么都没有收到。 我使用2个模拟器来测试它,但我不认为这是问题。偏偏我没有手机用andoid一个瞬间:(安卓:未收到SMS发送的确认在模拟器

我的代码如下所示:

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

回答

6

按照"SMS Messaging in Android"-tutorial on mobiforge.com,发送状态报告没有模拟器工作:

当成功传递,它会显示一个“发送短信”的消息请注意,使用模拟器,当短信成功发送,则“短信发送”消息未出现测试;真正这只作品装置。

+0

多么可怜buzinga! – ruben 2013-09-19 12:46:11

+0

这个链接是死 – joao2fast4u 2015-12-30 11:43:46

+1

这就是为什么我引用的文章的相关部分,@ joao2fast4u – msal 2015-12-31 02:20:06