나는 개인적으로 게시하도록하겠습니다 코드를 테스트하지 않은,하지만 this other question에 대한 대답은 그래서 그것을 작동합니다 생각으로는 받아 들여졌다.
SmsManager smsMan = new SmsManager.getDefault();
ArrayList<String> contactList = new ArrayList();
//add contacts to contactList with contactList.add(string)
for (int i = 0; i <= contactList().size(); i++) {
String SENT = contactList.get(i).toString();// you could replace this with i,
//or something like "sms_sent_myappname" + i.toString());
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT, 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));
smsManager.sendTextMessage(contactList.get(i).toString(), null, message, sentPI, null);
}
위와 같은 방법으로 Android에 각 메시지를 차례로 보내 달라는 요청을 보내 게됩니다. 실제로 Activity.RESULT_OK
후 다음 SMS를 보낼 경우, 나는 ArrayList
방법을 사용하여 여전히 추천 할 것입니다, 대신 루프에 대한, 당신은 같은 것을 할 수 : 다시
public void onCreate(Bundle savedInstanceState) {
smsMan = new SmsManager.getDefault(); //assuming you declared SmsManager smsMan in class body.
contactList = new ArrayList(); //assuming you declared ArrayList<String> contactList in class body.
//add contacts to contactList with contactList.add(string);
}
public void sendSms(int position){
//add contacts to contactList with contactList.add(string)
String SENT = contactList.get(position).toString();// you could replace this with i,
//or something like "sms_sent_myappname" + i.toString());
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT, 0);
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK
context.unregisterReceiver(this);
i++;
if (contactList.size()<i){
sendSms(i);
} else {
//You are done sending - Do what you want.
}
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));
smsManager.sendTextMessage(contactList.get(position).toString(), null, message, sentPI, null);
}
합니다. 나는 그것을 테스트하지 않았지만 효과가있다. 더 이상 질문이 있거나 내가 무엇에 대해 불분명한지 알려주십시오.
코드가 재귀로 이어지고 있습니다. 그 효과에 대해 걱정하고 있습니다. 그러나 나는 그것을 구현하고 여기에 게시 할 경우 .. – Vikas
@Vikas 미안 해요. 나는 처음 게시물에 코드를 엉망으로 만들었다. 이제 첫 번째 블록과 두 번째 블록을 모두 업데이트하여 코드가 필요한 방식을 구현했습니다. 나는 이것이 더 많은 도움이되기를 바랍니다. – Jakar
감사합니다. 괜찮습니다. 첫 번째 게시물에 귀하의 요지가 있습니다. 내가 그 코드를했지만 비슷한 문제가., 6 SMS를 보낸 후, 내 서비스가 충돌 ... 나는 (여분의 코드를 제거하는) 새로운 프로젝트를 만들고, 당신이 그걸로 놀 수 있도록 당신에게 우편을 제공하려고 노력하고있어. – Vikas