Provide a dialog box with a list for users to select the recipient number of the mass SMS, the program uses a Arraylist<string> collection to save all the recipient's number
In order to realize the mass function, the program loops through the numbers in the ArrayList and sends a text message to each number in turn.
public class Mainactivity extends Activity {EditText numbers, content; Button Select, send; Smsmanager smsmanager;//record list arraylist<string> sendlist = new arraylist<string> (); @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Smsmanager = Smsmanager.getdefault (); numbers = (EditText) Findviewbyid (r.id.numbers); content = (EditText) Findviewbyid (r.id.content); select = (Button) Findviewbyid (r.id.select); send = (Button) Findviewbyid (r.id.send); Send.setonclicklistener (New Onclicklistener () {@SuppressWarnings ("deprecation") @Overridepublic void OnClick (View v) {//One to send SMS for (String number:sendlist) {pendingintent pi = pendingintent.getactivity (mainactivity.this, 0, new Intent (), 0); smsmanager.sendtextmessage (number, NULL, Content.gettext (). toString (), pi, null);} Toast.maketext (mainactivity.this, "Bulk SMS Completion", 8000). Show ();}); /Select Contact Select.setonclicklistener (new Onclicklistener () {@Overridepublic voiD OnClick (View v) {//query contact's phone number//Contentresolver.query (URI Uri, string[] projection, string//selection, string[] Select Ionargs, String sortOrder) final Cursor cursor = getcontentresolver (). Query ( Contactscontract.commondatakinds.phone.content_uri,null, NULL, NULL, NULL); Baseadapter adapter = new Baseadapter () {@Overridepublic int getcount () {//TODO auto-generated method Stubreturn CURSOR.G Etcount ();} @Overridepublic Object getItem (int position) {//TODO auto-generated method Stubreturn position;} @Overridepublic long Getitemid (int position) {//TODO auto-generated method Stubreturn position;} @Overridepublic view GetView (int position, view Convertview,viewgroup parent) {cursor.movetoposition (position); CheckBox RB = new checkbox (mainactivity.this);//Get the phone number of the contact, and remove the middle dash, space string numbers = Cursor.getstring ( Cursor.getcolumnindex (CommonDataKinds.Phone.NUMBER)). Replace ("-", ""). Replace ("", ""); Rb.settext (number); if ( isChecked (number)) {rb.setchecked (true);} Return rb;}};/ /load the list.xml layout file corresponding VIew interface View Selectview = Getlayoutinflater (). Inflate (r.layout.list,null);//Get the ListView component named List in Selectview final ListView ListView = (ListView) Selectview.findviewbyid (R.id.list); Listview.setadapter (adapter); new Alertdialog.builder (mainactivity.this). Setview (Selectview). Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (Dialoginterface dialog,int which) {// Empty sendlist.clear ();//traverse the ListView component for each list item for (int i = 0; i < Listview.getcount (); i++) {checkbox checkbox = (checkbox) L Istview.getchildat (i);//If the list item is checked if (checkbox.ischecked ()) {//Adds the list item's phone number Sendlist.add (Checkbox.gettext (). ToString ());}} Numbers.settext (Sendlist.tostring ());}}). Show ();}}); Determines whether a number is within the mass range public boolean isChecked (string phone) {for (string s1:sendlist) {if (S1.equals (phone)) {return true;} }return false;}}
Android------sms mass function