Android --- 47 --- SMS group function, android --- 47 ---

Source: Internet
Author: User

Android --- 47 --- SMS group function, android --- 47 ---

A dialog box with a list is provided for you to select the number of recipients who send Group messages. The program uses an ArrayList <String> set to save the number of all recipients.
To implement the group function, the program cyclically traverses the numbers in the ArrayList and sends SMS messages 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) {// send text messages one by one 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, "message sending completed", 8000 ). show () ;}}); // select the contact. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {// query the contact's phone number // ContentResolver. query (Uri uri, String [] projection, String // selection, String [] selectionArgs, String sortOrder) final Cursor cursor = getContentResolver (). query (ContactsContract. commonDataKinds. phone. CONTENT_URI, null, null); BaseAdapter adapter = new BaseAdapter () {@ Overridepublic int getCount () {// TODO Auto-generated method stubreturn cursor. getCount () ;}@ 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); // obtain the contact's phone number, and remove the middle strip and space String number = cursor. getString (cursor. getColumnIndex (CommonDataKinds. phone. NUMBER )). replace ("-",""). replace ("", ""); rb. setText (number); if (isChecked (number) {rb. setChecked (true) ;}return rb ;}; // load list. view page corresponding to the xml layout file: View selectView = getLayoutInflater (). inflate (R. layout. list, null); // obtain the list component final ListView = (listView) selectView in 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) {// clear sendlist. clear (); // traverse each list item of the listView component for (int I = 0; I <listView. getCount (); I ++) {CheckBox checkBox = (CheckBox) listView. getChildAt (I); // if this list item is checked if (checkBox. isChecked () {// Add the phone number sendlist for this list item. add (checkBox. getText (). toString () ;}} numbers. setText (sendlist. toString ());}}). show () ;}}) ;}// determine whether a number is in the group range public boolean isChecked (String phone) {for (String s1: sendlist) {if (s1.equals (phone) {return true ;}} return false ;}}



Zookeeper

Related Article

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.