2014-01-31 25 views
6

使用SMS短信经理,我使用SMS管理器来发送短信给多个用户,但我得到RESULT_ERROR_GENERIC_FAILURE(一般故障)。如何解决这个问题?RESULT_ERROR_GENERIC_FAILURE回报,同时发送android系统

// ---sends an SMS message to another device--- 
private void sendSMS(String phoneNumber, String message) { 
    String SENT = "SMS_SENT"; 
    String DELIVERED = "SMS_DELIVERED"; 

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
      SENT), 0); 

    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, 
      new Intent(DELIVERED), 0); 

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

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

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

在这里,我使用SmsManager和sendSms()采取数量和消息作为参数。

+1

发布您的logcat和相关代码。 –

+0

我在上面添加了@Shayanpourvatan的来源 –

+0

你是在手机上还是在模拟器上看到这个错误? GENERIC_FAILURE通常与一些内部无线电问题 –

回答

1

可能是你应该缩短你的短信身体以适应仅1 SMS(这是只有160 charachters),我使用相同的代码时,我缩短下160短信&得到了确切的同样的错误&,它已成功发送:)

0

如果你的邮件正文包含超过160个字符,您需要发送短信的多部分。