发送短信到号码的Array

发送短信到号码的Array

本文介绍了发送短信到号码的Array - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林正试图发送短信到号码在Android的数组但短信只发送到阵列中的第一个号码。可能是什么回事?

Im am trying to send a SMS to an array of numbers in Android however the SMS is only being sent to the first number in the array. What could be going wrong?

下面是我的code:

                        android.telephony.SmsManager shortMessageManager;
                    shortMessageManager = SmsManager.getDefault();

                    // Get DB
                    dbTools = new DBTools(MainActivity.this);

                    // Get array
                    ArrayList<String> phoneNumberArray = dbTools
                            .getAllphoneNumbers();



                    String SMSNumbers = phoneNumberArray.toString();


                    String message = "Hello from Android";
                    try {
                        // Do something
                        shortMessageManager.sendTextMessage(SMSNumbers,
                                null, message, null, null);
                        Log.d("PhoneNo", SMSNumbers);
                    } catch (Exception e) {
                        Log.d("PhoneNo", "fail");
                    }

我记录SMSNumbers,它输出由一个分隔的阵列中的每个号码,和一个空间。

I've logged the "SMSNumbers" and it outputs each number in the array seperated by a , and a space.

推荐答案

我将我的ArrayList到一个数组,然后创建一个循环来发送短信

I converted my ArrayList to an Array and then created a loop to send out the SMS

                        android.telephony.SmsManager shortMessageManager;
                shortMessageManager = SmsManager.getDefault();

                // Get DB
                dbTools = new DBTools(MainActivity.this);

                // Get array
                ArrayList<String> phoneNumberArray = dbTools
                        .getAllphoneNumbers();



         String[] SMSNumbers = phoneNumberArray.toArray(new String[phoneNumberArray.size()]);


                String message = "Hello from Android";


                    try {
                        // Do something
                        for(int i=0;i<SMSNumbers.length;i++){
                            Thread.sleep(3000);
                        shortMessageManager.sendTextMessage(SMSNumbers[i],
                                null, message, null, null);
                        Log.d("PhoneNo",SMSNumbers[i]);
                        }
                    } catch (Exception e) {
                        Log.d("PhoneNo", "fail");
                    }

这篇关于发送短信到号码的Array - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:35