[android] send sms to multiple address

여러 명에게 sms를 보내야하는데, 이상하게 가장 처음 번호로만 문자가 전송되고, 나머지 사람들은 RESULT_ERROR_NO_SERVICE 가 돌아왔다.
검색해봐도 해결책이 안나와서 그냥 시간을 두고 전송되게 수정했다.
문제 생기면 더 늦추지 뭐…

private static final String SMS_SENT = "SMS_SENT";
private static final String SMS_DELIVERED = "SMS_DELIVERED";

@Override
protected void onStop()
{
   super.onStop();
   try
   {
      unregisterReceiver(sentReceiver);
      unregisterReceiver(deliveryReceiver);
   }
   catch (Exception e)
   {
      e.printStackTrace();
   }
}

private void sendSMS()
{
   final PendingIntent sentPI = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(SMS_SENT), 0);
   final PendingIntent deliveryPI = PendingIntent.getBroadcast(getApplicationContext(), 1, new Intent(SMS_DELIVERED), 1);

   registerReceiver(sentReceiver, new IntentFilter(SMS_SENT));
   registerReceiver(deliveryReceiver, new IntentFilter(SMS_DELIVERED));

   final SmsManager sms = SmsManager.getDefault();

   final String message = "message";
   String[] people = {"1111", "1234", "01412345678"};
   for (int i = 0; i < people.length; i++)
   {
      final String phone = people[i];

      Runnable runn = new Runnable()
      {
         @Override
         public void run()
         {
            sms.sendTextMessage(phone, null, message, sentPI, deliveryPI);
         }
      };
      Handler handler = new Handler();
      handler.postDelayed(runn, i * 5000); // 시간이 너무 짧으면 첫 번째 번호로만 전송되고, 나머지는 RESULT_ERROR_NO_SERVICE 가 온다. 
   }
}

private BroadcastReceiver sentReceiver = new BroadcastReceiver()
{
   @Override
   public void onReceive(Context context, Intent intent)
   {
      switch (getResultCode())
      {
         case RESULT_OK:
            Log.i("MainActivity.java | onReceive", "|" + "result _ok" + "|");
            break;

         case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            Log.w("MainActivity.java | onReceive", "|" + "SmsManager.RESULT_ERROR_GENERIC_FAILURE:" + "|");
            break;

         case SmsManager.RESULT_ERROR_NO_SERVICE:
            Log.w("MainActivity.java | onReceive", "|" + "SmsManager.RESULT_ERROR_NO_SERVICE" + "|");
            break;

         case SmsManager.RESULT_ERROR_NULL_PDU:
            Log.w("MainActivity.java | onReceive", "|" + "SmsManager.RESULT_ERROR_NULL_PDU" + "|");
            break;

         case SmsManager.RESULT_ERROR_RADIO_OFF:
            Log.w("MainActivity.java | onReceive", "|" + "SmsManager.RESULT_ERROR_RADIO_OFF:" + "|");
            break;

         default:
            Log.w("MainActivity.java | onReceive", "| =====" + getResultCode() + "|");
            break;
      }
   }
};

private BroadcastReceiver deliveryReceiver = new BroadcastReceiver()
{
   @Override
   public void onReceive(Context context, Intent intent)
   {
      switch (getResultCode())
      {
         case RESULT_OK:
            Log.i("MainActivity.java | onReceive", "|" + "RESULT_OK" + "|");
            break;

         case RESULT_CANCELED:
            Log.w("MainActivity.java | onReceive", "|" + "RESULT_CANCELED:" + "|");
            break;

         default:
            Log.w("MainActivity.java | onReceive", "| +++++++" + getResultCode() + "|");
            break;
      }
   }
};

 

 

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