Android------sms mass function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.