文本短信未发送,即使吐司显示已发送

text sms isn't being sent, even though toast shows that it's sent

我正在尝试向我 ArrayList 中的所有联系电话发送短信。我的代码如下:

try{

    SmsManager sms = SmsManager.getDefault();

    if (customarray.size() != 0) {

          Log.d("contact",String.valueOf(customarray)); //shows all the contact numbers 

          for (int i = 0; i < customarray.size(); i++) {

             Log.d("contact",String.valueOf(customarray.get(i))); //shows each of the contact numbers

             sms.sendTextMessage(customarray.get(i), null, string, null, null);

             Toast.makeText(contacts.this,"Your sms has been sent to "+customarray.get(i),Toast.LENGTH_SHORT).show();

          }
    }

   } catch (Exception e) {

          e.printStackTrace();

   }

我还在清单文件中添加了权限:

<uses-permission android:name="android.permission.SEND_SMS" />

此处,customarray包含所有联系电话。即使吐司出现,“您的短信已发送至...”,但短信永远不会发送。为什么?

根据@Joachim Sauer 的建议,使用 PendingIntent 有效:

try{

    SmsManager sms = SmsManager.getDefault();

    Intent intent=new Intent(getApplicationContext(),contacts.class);

    PendingIntent pi= PendingIntent.getActivity(getApplicationContext(), 0, intent,0);

    if (customarray.size() != 0) {

          Log.d("contact",String.valueOf(customarray)); //shows all the contact numbers 

          for (int i = 0; i < customarray.size(); i++) {

             Log.d("contact",String.valueOf(customarray.get(i))); //shows each of the contact numbers

             sms.sendTextMessage(customarray.get(i), null, string, pi, null);

             Toast.makeText(contacts.this,"Your sms has been sent to "+customarray.get(i),Toast.LENGTH_SHORT).show();

          }
    }

   } catch (Exception e) {

          e.printStackTrace();

   }