博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android 短信群发
阅读量:5769 次
发布时间:2019-06-18

本文共 4345 字,大约阅读时间需要 14 分钟。

直奔主题~!

结构如图:

person_content.java代码:

public class person_content extends ListActivity {	private Button submit_result_btn;	private HashMap
al; @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); CheckBox cb = (CheckBox) v.findViewById(R.id.cb); TextView username_txt = (TextView) v.findViewById(R.id.username); TextView phonenum_txt = (TextView) v.findViewById(R.id.tel_num); String username = username_txt.getText().toString(); String phonenum = phonenum_txt.getText().toString(); cb.setEnabled(true); if (cb.isChecked()) { cb.setChecked(false); al.remove(phonenum); } else { cb.setChecked(true); al.put(phonenum, username); } cb.setEnabled(false); } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.show_contacts); bind(); } public void bind() { al = new HashMap
(); submit_result_btn = (Button) this.findViewById(R.id.submit_result_btn); Cursor ps_cs = getContentResolver().query(People.CONTENT_URI, null, null, null, null); startManagingCursor(ps_cs); String[] string = { Phones.NAME, Phones.NUMBER }; int[] intText = { R.id.username, R.id.tel_num }; SimpleCursorAdapter sca = new SimpleCursorAdapter(person_content.this, R.layout.person_content, ps_cs, string, intText); setListAdapter(sca); submit_result_btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent it = new Intent(); Bundle bd = new Bundle(); bd.putSerializable("select_people", al); it.putExtras(bd); setResult(1, it); finish(); } }); }}

Sms_Send_AllActivity.java代码:

public class Sms_Send_AllActivity extends Activity {	@Override	protected void onActivityResult(int requestCode, int resultCode, Intent data) {		// TODO Auto-generated method stub		// super.onActivityResult(requestCode, resultCode, data);		if (requestCode == 0) {			if (resultCode == 1) {				Bundle bd = data.getExtras();				al = (HashMap
) bd .getSerializable("select_people"); } } } private Button select_btn; private Button send_btn; private EditText content_txt; private HashMap
al; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findAll(); bind(); } public void findAll() { select_btn = (Button) this.findViewById(R.id.People_btn); send_btn = (Button) this.findViewById(R.id.submit_btn); content_txt = (EditText) this.findViewById(R.id.content_txt); } public void bind() { select_btn.setOnClickListener(mylistener); send_btn.setOnClickListener(mylistener); } private View.OnClickListener mylistener = new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.People_btn: Intent it = new Intent(Sms_Send_AllActivity.this, person_content.class); startActivityForResult(it, 0); break; case R.id.submit_btn: String content = content_txt.getText().toString(); SmsManager sm = SmsManager.getDefault(); for (Iterator iter = al.entrySet().iterator(); iter.hasNext();) { Map.Entry element = (Entry) iter.next(); String number = element.getKey().toString(); // 这句目的是为了在模拟器上真实模拟 number = number.replace("-", "").trim(); String name = element.getValue().toString(); PendingIntent sentIntent = PendingIntent.getBroadcast( Sms_Send_AllActivity.this, 0, new Intent(), 0); sm.sendTextMessage(number, null, content, sentIntent, null); } Toast.makeText(Sms_Send_AllActivity.this, "发送成功", Toast.LENGTH_LONG).show(); break; default: break; } } };}

main.xml代码:

person_content.xml代码:

show_contacts.xml代码:

androidManifest.xml代码:

转载于:https://www.cnblogs.com/jason-jo/archive/2011/09/16/2179043.html

你可能感兴趣的文章
UML类图中的六种关系
查看>>
探寻Interpolator源码,自定义插值器
查看>>
一致性哈希
查看>>
mysql(待整理)
查看>>
看雪论坛502,出现安全宝?
查看>>
使用PullToRefresh实现下拉刷新和上拉加载
查看>>
mysql
查看>>
2012年电信业八大发展趋势
查看>>
Web日志安全分析工具 v2.0发布
查看>>
JS重载
查看>>
python2和python3同安装在Windows上,切换问题
查看>>
php加速工具xcache的安装与使用(基于LNMP环境)
查看>>
android超链接
查看>>
redhat tomcat
查看>>
统计数据库大小
查看>>
IO流的学习--文件夹下文件的复制
查看>>
第十六章:脚本化HTTP
查看>>
EXCEL表中如何让数值变成万元或亿元
查看>>
Cisco PIX防火墙的安装流程
查看>>
配置系列:ssm中applicationContext-mybatis.xml的简单配置
查看>>