群发短信并监控成功与否
2015-08-12 12:29
477 查看
package com.example.contacttest;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Context context;
PendingIntent sendIntent;
PendingIntent backIntent;
String []tel={"",""};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context=getApplicationContext();
//处理返回的发送状态
String SENT_SMS_ACTION = "SENT_SMS_ACTION";
Intent sentIntent = new Intent(SENT_SMS_ACTION);
sendIntent= PendingIntent.getBroadcast(context, 0, sentIntent,
0);
// register the Broadcast Receivers
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(context,
"短信发送成功", Toast.LENGTH_SHORT)
.show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
break;
}
}
}, new IntentFilter(SENT_SMS_ACTION));
//处理返回的接收状态
String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION";
// create the deilverIntent parameter
Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
backIntent= PendingIntent.getBroadcast(context, 0,
deliverIntent, 0);
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
Toast.makeText(context,
"收信人已经成功接收", Toast.LENGTH_SHORT)
.show();
}
}, new IntentFilter(DELIVERED_SMS_ACTION));
Button button=(Button)
4000
findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
for(int i=0;i<tel.length;i++)
{
sendSMS(tel[i], "test");
}
}
});
}
/**
* 调用短信接口发短信,含接收报告和发送报告
*
* @param phoneNumber
* @param message
*/
public void sendSMS(String phoneNumber, String message) {
// 获取短信管理器
android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
// 拆分短信内容(手机短信长度限制)
List<String> divideContents = smsManager.divideMessage(message);
for (String text : divideContents) {
smsManager.sendTextMessage(phoneNumber, null, text, sendIntent, backIntent);
}
}
}
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Context context;
PendingIntent sendIntent;
PendingIntent backIntent;
String []tel={"",""};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context=getApplicationContext();
//处理返回的发送状态
String SENT_SMS_ACTION = "SENT_SMS_ACTION";
Intent sentIntent = new Intent(SENT_SMS_ACTION);
sendIntent= PendingIntent.getBroadcast(context, 0, sentIntent,
0);
// register the Broadcast Receivers
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(context,
"短信发送成功", Toast.LENGTH_SHORT)
.show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
break;
}
}
}, new IntentFilter(SENT_SMS_ACTION));
//处理返回的接收状态
String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION";
// create the deilverIntent parameter
Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
backIntent= PendingIntent.getBroadcast(context, 0,
deliverIntent, 0);
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
Toast.makeText(context,
"收信人已经成功接收", Toast.LENGTH_SHORT)
.show();
}
}, new IntentFilter(DELIVERED_SMS_ACTION));
Button button=(Button)
4000
findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
for(int i=0;i<tel.length;i++)
{
sendSMS(tel[i], "test");
}
}
});
}
/**
* 调用短信接口发短信,含接收报告和发送报告
*
* @param phoneNumber
* @param message
*/
public void sendSMS(String phoneNumber, String message) {
// 获取短信管理器
android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
// 拆分短信内容(手机短信长度限制)
List<String> divideContents = smsManager.divideMessage(message);
for (String text : divideContents) {
smsManager.sendTextMessage(phoneNumber, null, text, sendIntent, backIntent);
}
}
}
相关文章推荐
- centos双系统恢复windows启动项
- CentOS 6.3下配置multipah
- win10装centos双系统之后,win10的启动项消失的解决方法
- windows中间vmware的Linux系统安装jdk步骤
- Paratroopers
- 使用Apache的ab工具进行压力测试
- Paratroopers
- Nginx服务器不支持PATH_INFO的问题及解决办法
- 正向代理和反向代理
- LNMP--Nginx禁止指定user_agent
- 网站建设与维护常识
- Open Auth辅助库(使用ImitateLogin实现登录)
- arm linux 分区
- Linux下find命令用法小结
- linux(debian/ubuntu)下连接安卓手机--小米4为例
- tomcat connector运行模式,优化tomcat运行性能
- 制作企业网站要关注哪些问题
- Linux下各种性能监控的命令(整理)
- linux sfdisk partition
- hadoop学习笔记 HIVE