如何发送短信到多个联系人和得到的结果code在Android的每个人 [英] How to send sms to multiple contacts and get the result code for each of them in android

查看:233
本文介绍了如何发送短信到多个联系人和得到的结果code在Android的每个人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的链接将告诉您如何发送短信到单个联系人,并得到结果code 链接

Below link tells how to send sms to single contact and get resultcodelink

但如何在Android中发送短信到多个联系人和得到的结果code为他们每个人

but How to send sms to multiple contacts and get the result code for each of them in android

推荐答案

您可以使用一个for循环,并创建一个新的BroadcastReceiver每个循环执行的时间,并有联系人列表是一个数组列表,每次发送该消息为新联系人,使用contactList.get(I)如下:

You could use a for loop and create a new BroadcastReceiver each time the for loop executes, and have the contact list be an array list, and each time you send the message to a new contact, use contactList.get(i) as follows:

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

我没有测试过,但似乎这是可行的。

I haven't tested it, but it seems like it would work.

这篇关于如何发送短信到多个联系人和得到的结果code在Android的每个人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆