使用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 用户更为频繁的连接 ...
随机推荐
- 2013 Multi-University Training Contest 6
HDU-4655 Cut Pieces 题意:有N个格子能够被涂色,每个格子能够涂1-ai 种颜色,当N=6,涂色方案:112233 认为方案中共有3个颜色块:涂色方案:121212 认为方案中共有6 ...
- linux之od命令
od [OPTION]... [FILE]... 把文件用8进制或者其他的格式显示出来.通常用于查看特殊格式文件的内容. 这个命令默认把文件的内容用八进制的形式清晰地写在标准输出上.如果是多个文件 ...
- Ruby方法
Ruby 方法 Ruby 方法与其他编程语言中的函数类似.Ruby 方法用于捆绑一个或多个重复的语句到一个单元中. 方法名应以小写字母开头.如果您以大写字母作为方法名的开头,Ruby 可能会把它当作常 ...
- openwrt: Makefile 框架分析
openwrt: Makefile 框架分析 原文链接:blog.chinaunix.net/uid-26675482-id-4704952.html 本篇的主要目的是想通过分析Makefile,了解 ...
- SDL2.0的SDL_Event事件处理
SDL_Event事件集合 SDL_AudioDeviceEvent SDL_ControllerAxisEvent SDL_ControllerButtonEvent SDL_ControllerD ...
- SDL1.2到2.0的迁移指南(转)
里面有些单词不好翻译所以放在开头,以备查验. BLock Image Transfer, a computer graphics operation in which two bitmap patte ...
- js 删除多个相同name元素。
var obj = document.getElementsByName("abc"); for(var i = 0;i<(obj.length) * 2;i++){ obj ...
- Perl 语法 - 基础
perl语言的核心是正则表达式,在文本处理上非常有优势,与python类似,但语法不同,perl的语法很灵活,用多了才会觉得好用. 常用知识点总结: perl语法类似于C语言(perl源于Unix), ...
- Tiny PXE Server简介
Tiny PXE Server简介Tiny PXE Server是一款小巧而功能强大的网启软件.支持DHCP TFTP HTTP BINL DNS等多个协议,支持grub4dos,pxelinux,i ...
- Qt之findChild
简述 在Qt编程过程中,通常会有多个部件嵌套,而大多数部件都有父子依赖关系,但是有些情况下不能直接引用子部件,这时我们可以通过父部件来findChild -"查找孩子". 简述 查 ...