发送短信到循环使用多个联系人 [英] sending sms to multiple contacts using loop

查看:179
本文介绍了发送短信到循环使用多个联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在Android短信application.I需要发送短信到多个contact.There可发送短信到多接触,所以我用loop.The下面的方法是我的code。

I am working on an android sms application.I have to send sms to multiple contact.There is method available to send sms to multi contacts so i used for loop.The following is my code.

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

                sendSms(to_nums.get(i),  snd_txt.getText().toString() );


        }

public void sendSms(final String phoneNumber, final 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 --

    sendBroadcastReceiver=new BroadcastReceiver() {


        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            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;



                default:
                    break;
            }
            context.unregisterReceiver(this);

        }
    };



    registerReceiver(sendBroadcastReceiver , new IntentFilter(SENT));






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





}

但是,当我运行我的code我正在一个例外,那说,接收器未注册。单除非法律它的工作原理Fone公司。 我。怎么可以注册和注销的顺序?请帮我的朋友。

But when I am running my code I am getting an exception ,that says 'Receiver not registered'. for single receipient it works fone. .How can I register and unregister in order? Please help me friends.

推荐答案

您可以看看这些:

<一个href="http://stackoverflow.com/questions/11840057/sending-sms-to-multiple-contacts-stored-in-a-textview">Sending短信存储在一个TextView 多个联系人

<一个href="http://stackoverflow.com/questions/7092136/how-to-send-sms-to-multiple-contacts-and-get-the-result-$c$c-for-each-of-them-in">How发送短信到多个联系人和得到的结果code为他们每个人的机器人

在安卓发送短信给多人

这篇关于发送短信到循环使用多个联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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