使用SMSManager短信管理器实现短信群发
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;
//记录需要群发的号码列表
ArrayList<String> sendList = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sManager = SmsManager.getDefault();
//获取界面上的文本框、按钮组件
numbers = (EditText) findViewById(R.id.numbers);
content = (EditText) findViewById(R.id.content);
select = (Button) findViewById(R.id.search);
send = (Button) findViewById(R.id.send);
//为send按钮的单击事件绑定监听器
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
for(String number : sendList){
//创建一个PendingIntent对象
PendingIntent pi = PendingIntent.getActivity(
GroupSend.this, 0, new Intent(),0);
//发送短信
sManager.sendTextMessage(number, null,
content.getText().toString(), pi, null);
}
//提示短信群发完成
Toast.makeText(GroupSend.this, "短信群发完成!", 8000).show();
}
});
//为select按钮的单击事件绑定监听器
select.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 查询联系人的电话号码
final Cursor cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, null, null, null);
BaseAdapter adapter = new BaseAdapter() {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
cursor.moveToPosition(position);
CheckBox rb = new CheckBox(GroupSend.this);
//获取联系人的电话号码,并去掉中间的中划线
String number = cursor.getString(
cursor.getColumnIndex(ContactsContract.
CommonDataKinds.Phone.NUMBER)).replace("-", "");
rb.setText(number);
//如果该号码已经被加入发送人名单,默认勾选该号码
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();
}
};
//加载list.xml布局文件对应的View
View selectView = getLayoutInflater().inflate(
R.layout.list, null);
//获取selectView中的名为list的ListView组件
final ListView listView =
(ListView) selectView.findViewById(R.id.list);
listView.setAdapter(adapter);
new AlertDialog.Builder(GroupSend.this).setView(selectView)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 清空sendList集合
sendList.clear();
//遍历ListView组件的每个列表项
for(int i = 0 ;i<listView.getCount();i++){
CheckBox checkBox = (CheckBox) listView.getChildAt(i);
//如果该列表项被勾选
if(checkBox.isChecked()){
//添加该列表项的电话号码
sendList.add(checkBox.getText().toString());
}
}
numbers.setText(sendList.toString());
}
}).show();
}
});
}
//判断某个号码是否已在群发范围内
public boolean isChecked(String phone){
for(String s1 : sendList){
if(s1.equals(phone)){
return true;
}
}
return false;
}
}
使用SMSManager短信管理器实现短信群发的更多相关文章
- 使用SMSManager短信管理器发送短信
import android.os.Bundle;import android.app.Activity;import android.app.PendingIntent;import android ...
- android之短信拦截器
下面通过短信拦截器来介绍短信中的广播 布局文件 在布局文件中可以设置需要拦截的号码 <?xml version="1.0" encoding="utf-8" ...
- Android短彩信源码解析-短信发送流程(二)
转载请注明出处:http://blog.csdn.net/droyon/article/details/11699935 2,短彩信发送framework逻辑 短信在SmsSingleRecipien ...
- 短信平台软件开发,短信发送平台销售,短信软件源码,G客短信发送平台
一:web短信平台组成 需要短信软件平台源码的联系QQ:290615413 vx:290615413 整套短信系统平台还是由B/S(客户端+后台,取消了以前C/S的管理后台) ,C/S发送服务端和 ...
- yii框架中验证器声明一组内置验证器可以使用短名称引用
1.内置验证器的短名称分别有: boolean: yii\validators\BooleanValidator captcha: yii\captcha\CaptchaValidator compa ...
- PHP短信发送服务 youe短信企业服务
/** * 通用短信平台HTTP接口POST方式发送短信实例 * 返回字符串 * 一般情况下调用此方法 */ function postSendMessage($msgContents,$phoneL ...
- Android提供的系统服务之--TelephonyManager(电话管理器)
Android提供的系统服务之--TelephonyManager(电话管理器) 转载请注明出处--coder-pig TelephonyManager的作用: 用于管理手机通话状态,获取电话信息(设 ...
- Node.js包管理器Yarn的入门介绍与安装
FAST, RELIABLE, AND SECURE DEPENDENCY MANAGEMENT. 就在昨天, Facebook 发布了新的 node.js 包管理器 Yarn 用以替代 npm .咱 ...
- WebSphere--连接管理器
连接管理器使您可以控制并减少由 Web 应用程序使用的资源.相对于非 Web 应用程序,基于 Web 的应用程序对数据服务器的访问会导致更高的和不可预料的系统开销,这是由于 Web 用户更为频繁的连接 ...
随机推荐
- ABAP 没有地方输入\H 进入DEBUG 怎么办?
把如下代码保存,命名debug.txt ,把这个文件拖拉到要调试的窗口. [FUNCTION]Command=/HTitle=Barry TestType=SystemCommand
- FileCopy
/*[入]指的是到内存里,[出]指的是到内存外*/ import java.io.*; public class MyReadFile{ public static void main(String[ ...
- [转载] 为 Key-Value 数据库实现 MVCC 事务
http://mp.weixin.qq.com/s?__biz=MzA5ODM5MDU3MA==&mid=400086920&idx=1&sn=b8174184059e2886 ...
- thinkphp分页效果的制作,按查询条件分页正确做法
PHP代码: <?php namespace Home\Controller; use Think\Controller; use Home\Clas\Cate; class IndexCont ...
- 在map中根据value获取key
原文:http://blog.csdn.net/mexican_jacky/article/details/51789548 //根据map的value获取map的key private static ...
- commonJS — 通用方法(for COM)
for COM github: https://github.com/laixiangran/commonJS/blob/master/src/forCOM.js 代码 /** * Created b ...
- html list <==> unformatted list
两者的区别很大不得不擦呢,任何两个东西的差别都很大,不得混淆.---一个有ul/ol的选择,一个没有
- Machine Learning - 第5周(Neural Networks: Learning)
The Neural Network is one of the most powerful learning algorithms (when a linear classifier doesn't ...
- VB6 GDI+ 入门教程[7] Graphics 其他内容
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[7] Graphics 其他内容 2009 年 9 月 ...
- Windows高精度时间
目录 第1章计时 1 1.1 GetTickCount 1 1.2 timeGetTime 1 1.3 QueryPerformanceCounter 1 1.4 测试 ...