Import java.util.ArrayList;
Import Android.os.Bundle;
Import Android.provider.ContactsContract;
Import android.app.Activity;
Import Android.app.AlertDialog;
Import android.app.PendingIntent;
Import Android.content.DialogInterface;
Import android.content.Intent;
Import Android.database.Cursor;
Import Android.telephony.SmsManager;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.view.View.OnClickListener;
Import Android.widget.BaseAdapter;
Import Android.widget.Button;
Import Android.widget.CheckBox;
Import Android.widget.EditText;
Import Android.widget.ListView;
Import Android.widget.Toast;
public class Groupsend extends Activity {
EditText numbers;
EditText content;
Button Select;
Button send;
Smsmanager Smanager;
Record a list of numbers that need to be mass
arraylist<string> sendlist = new arraylist<string> ();
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Smanager = Smsmanager.getdefault ();
Get text boxes, button components on the interface
Numbers = (EditText) Findviewbyid (r.id.numbers);
Content = (EditText) Findviewbyid (r.id.content);
select = (Button) Findviewbyid (R.id.search);
Send = (Button) Findviewbyid (r.id.send);
The Click event Binding Listener for the Send button
Send.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
for (String number:sendlist) {
Create a Pendingintent object
pendingintent pi = pendingintent.getactivity (
Groupsend.this, 0, New Intent (), 0);
Send SMS
Smanager.sendtextmessage (number, NULL,
Content.gettext (). toString (), pi, null);
}
Prompt SMS Mass complete
Toast.maketext (groupsend.this, "Bulk SMS completed! ", 8000). Show ();
}
});
The Click event Binding Listener for the Select button
Select.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Query the phone number of the contact person
Final cursor cursor = getcontentresolver (). Query (
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
NULL, NULL, NULL, or NULL);
Baseadapter adapter = new Baseadapter () {
@Override
Public View GetView (int position, View Convertview, ViewGroup parent) {
Cursor.movetoposition (position);
CheckBox RB = new checkbox (groupsend.this);
Get the phone number of the contact and remove the middle underline
String number = cursor.getstring (
Cursor.getcolumnindex (contactscontract.
CommonDataKinds.Phone.NUMBER). Replace ("-", "" ");
Rb.settext (number);
If the number has been added to the sender list, check the number by default
if (isChecked (number)) {
Rb.setchecked (TRUE);
}
return RB;
}
@Override
public long getitemid (int position) {
return position;
}
@Override
Public Object getItem (int position) {
return position;
}
@Override
public int GetCount () {
return Cursor.getcount ();
}
};
Load the list.xml layout file corresponding to the view
View Selectview = Getlayoutinflater (). Inflate (
R.layout.list, NULL);
Gets the ListView component named List in the Selectview
Final ListView ListView =
(ListView) Selectview.findviewbyid (r.id.list);
Listview.setadapter (adapter);
New Alertdialog.builder (Groupsend.this). Setview (Selectview)
. Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
Emptying the Sendlist collection
Sendlist.clear ();
Iterate through each list item of a ListView component
for (int i = 0; I<listview.getcount (); i++) {
CheckBox checkbox = (checkbox) listview.getchildat (i);
If the list item is checked
if (checkbox.ischecked ()) {
Add the phone number of the list item
Sendlist.add (Checkbox.gettext (). toString ());
}
}
Numbers.settext (Sendlist.tostring ());
}
}). Show ();
}
});
}
Determine if a number is within the mass range
public boolean isChecked (String phone) {
for (String s1:sendlist) {
if (s1.equals (phone)) {
return true;
}
}
return false;
}
}
Use Smsmanager SMS Manager for Mass SMS